Install Node.js

This guide explains how to install Node.js in your home directory without root access.

💡 Tip

You can install or update Node.js entirely within your home directory without affecting other users or requiring root privileges.

1. Log in to your account via SSH and make sure ~/bin is included in your PATH:

if ! grep -qw "PATH=\$HOME/bin" ~/.bashrc ; then mkdir -p ~/bin && echo "PATH=\$HOME/bin:\$PATH" >> ~/.bashrc && source ~/.bashrc ; fi

2. Download the Node.js package:

cd && wget -q https://nodejs.org/dist/v21.1.0/node-v21.1.0-linux-x64.tar.gz

3. Extract the archive into your home directory:

tar xf ~/node-v21.1.0-linux-x64.tar.gz --strip-components=1 -C ~/

4. Remove the downloaded archive:

rm -f ~/node-v21.1.0-linux-x64.tar.gz

5. Verify the installation:

node -v
npm -v
✔ Installation Complete

Node.js has been installed successfully and is ready to use.


Update Node.js

To update Node.js, simply download a newer version and extract it over the existing installation.

1. Download the new version:

cd && wget -q https://nodejs.org/dist/v21.1.0/node-v21.1.0-linux-x64.tar.gz

2. Extract the archive:

tar xf ~/node-v21.1.0-linux-x64.tar.gz --strip-components=1 -C ~/

3. Remove the downloaded archive:

rm -f ~/node-v21.1.0-linux-x64.tar.gz

4. Verify the installed version:

node -v
npm -v
✔ Update Complete

Node.js has been updated successfully.


Uninstall Node.js

If you installed Node.js using this guide, you can remove it by running the following commands:

rm -f ~/bin/node ~/bin/npm ~/bin/npx ~/bin/corepack
rm -rf ~/lib/node_modules/npm ~/lib/node_modules/corepack
rm -rf ~/include/node
rm -f ~/CHANGELOG.md ~/LICENSE ~/README.md
✔ Uninstallation Complete

Node.js has been removed successfully.


Verification

âš  Important

This installation is performed entirely inside your home directory and does not require root privileges. To install a different version, simply replace v21.1.0 in the download URL and all related commands with the version you want to install.

Was this answer helpful? 148 Users Found This Useful (272 Votes)