Skip to content

Instantly share code, notes, and snippets.

@realphongha
Last active January 8, 2024 07:02
Show Gist options
  • Save realphongha/3e98842736755f9e88ba57e793ae2b8e to your computer and use it in GitHub Desktop.
Save realphongha/3e98842736755f9e88ba57e793ae2b8e to your computer and use it in GitHub Desktop.
Install Nodejs on user directory
# https://www.johnpapa.net/node-and-npm-without-sudo/
VERSION=v18.18.0
DISTRO=linux-x64
wget https://nodejs.org/dist/$VERSION/node-$VERSION-$DISTRO.tar.xz
tar -xvf node-$VERSION-$DISTRO.tar.xz
rm node-$VERSION-$DISTRO.tar.xz
mkdir ~/.nodejs
mv node-$VERSION-$DISTRO ~/.nodejs
echo '# Nodejs' >> ~/.profile
echo 'VERSION=v18.18.0' >> ~/.profile
echo 'DISTRO=linux-x64' >> ~/.profile
echo 'export PATH=$HOME/.nodejs/node-$VERSION-$DISTRO/bin:$PATH' >> ~/.profile
. ~/.profile
node -v
npm -v
mkdir ~/.npm-packages
echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules:\$NODE_PATH\" >> ${HOME}/.bashrc
echo PATH=\"\$NPM_PACKAGES/bin:\$PATH\" >> ${HOME}/.bashrc
. ~/.bashrc
# upgrade node and npm
mkdir ~/.nodejs/n
export N_PREFIX=$HOME/.nodejs/n
npm i -g n && n lts && n prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment