Last active
January 8, 2024 07:02
-
-
Save realphongha/3e98842736755f9e88ba57e793ae2b8e to your computer and use it in GitHub Desktop.
Install Nodejs on user directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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