These are instructions for installing node as a normal user on one of our shared web hosting servers using nvm the Node Version Manager as recommended by the official Node.js developer website. You can also use nvm to install the npm Node Package Manager and install additional node packages.
To perform the rest of these steps you will need to login to the assigned host server for your website using ssh.
There might already be a version of node.js installed for your user. Use the command which to check its path.
user@host:~$ which node
/usr/bin/node
If the path is /usr/bin/node then this is the system wide version of node. Some servers might already include this. Check to see if the installed version of node.js meets your requirements and if so you may not need to bother with nvm.
user@host:~$ node -v
v10.24.0
If the node path includes your own home directory path then you may have already attempted to install node.js using another method. You should remove it to avoid conflicts with NVM.
Look for the latest release number on the Node Version Manager github site.
Copy the release number. Example: 40.1
Use curl command to download the latest NVM installer and run it with bash. Be sure to replace v0.40.1 in the example url below with the latest release number.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | XDG_CONFIG_HOME="$HOME/.config" bash
Setting the XDG_CONFIG_HOME enviroment variable makes sure the installer script installs its files in the ~/config/.nvm path and modifies ~/.bashrc to append the path to the nvm executable to your user PATH environment variable.
nvm --versionnvm --help to see a list of all commands.You can use nvm to list installable versions of node.js using ls-remote:
nvm ls-remote
Use the --lts argument to limit the list to Long Time Support versions of node.js
nvm list-remote --lts
Use grep to see just the latest within each major LTS version number.
nvm ls-remote --lts | grep Latest
Check the install instructions of your web application to determine what version of node.js it requires.
Choose the version you want and use that version as an argument to the install command. For example to install version 16.20.1
nvm install 16.20.1
Use the which see the full path where a specific version of Node.js was installed.
nvm which 16.20.1
To activate a specific version the use command modifies the PATH environment variable so that invoking the node command will run the correct version. You can switch between different installed node versions this way.
nvm use 16.20.1
Use node itself to check which version is active.
node --version
You can also confirm the current version of Node with nvm current.
nvm current
Make this version the default node version by assigning an alias. This modifies file .nvm/alias/default
nvm alias default 16.20.1
Use the same steps above to find and install newer versions of Node.js.
To list all of the currenlty the installed versions of Node.js
nvm ls
To uninstall a version of node.js you no longer require.
nvm uninstall 16.14.0
Attempt to install the latest working npm Node Package Manager for the current node version
nvm install-latest-npm