Node.js runs JavaScript programs on your service, and its package manager npm installs them. This guide installs the official Node.js in your home folder over SSH, without root access: SSH how to get connected.


1. Choose the Version

On nodejs.org, look up the newest LTS version; LTS versions get updates for the longest time. The commands below use v26.14.0; replace it with the version you choose, in every command.

2. Download and Check the Package

mkdir -p ~/software
cd ~/software
wget https://nodejs.org/dist/v26.14.0/node-v26.14.0-linux-x64.tar.xz https://nodejs.org/dist/v26.14.0/SHASUMS256.txt
grep " node-v26.14.0-linux-x64.tar.xz$" SHASUMS256.txt | sha256sum -c -

The last command compares the package with the checksum published by Node.js. It must answer:

node-v26.14.0-linux-x64.tar.xz: OK

3. Unpack It

mkdir ~/software/node
tar -xJf node-v26.14.0-linux-x64.tar.xz -C ~/software/node --strip-components=1
rm node-v26.14.0-linux-x64.tar.xz SHASUMS256.txt

4. Make the Commands Available

Add the folder of Node.js to your commands; your service reads this file when you log in:

echo 'PATH="$HOME/software/node/bin:$PATH"' >> ~/.profile

Log out of SSH and log in again. Then check:

node -v
npm -v
v26.14.0
11.21.3

5. Install Packages

Packages for a program go into its own folder. For example, create a project and install the package dayjs, which works with dates:

mkdir ~/myproject
cd ~/myproject
npm init -y
npm install dayjs
node -e "console.log(require('dayjs')().format('YYYY-MM-DD'))"

The last command prints today's date. The package is in ~/myproject/node_modules.

Programs you want to use as a command anywhere are installed with -g. They land in the folder of Node.js and work at once, for example:

npm install -g http-server
http-server --version

List your global packages with npm list -g --depth=0.

6. Update Node.js

Note your global packages with npm list -g --depth=0. Then remove the old version and install the new one with steps 2 and 3:

rm -r ~/software/node

After that, install your global packages again with npm install -g. The packages of your projects stay in their folders.

7. Remove Node.js

rm -r ~/software/node ~/.npm

Then open ~/.profile with nano ~/.profile and delete the line PATH="$HOME/software/node/bin:$PATH" at its end.


Good to Know

Was this answer helpful? 183 Users Found This Useful (318 Votes)