Every Pagely VPS has the standard Node.js package installed from the Ubuntu repository. The package manager for Node.js is npm, which is also installed. With these two tools installed on the system, you have the control to manage specific versions in the context of your own SSH user accounts and projects. We generally do not recommend changing the version installed globally on the system.
If you require a specific version of Node.js This article will discuss how to install n, the version management library for Node.js
What You'll Need
- A Pagely VPS
- An SSH user with access to your VPS
What You'll Need To Do
There will be seven steps:
- Log into the server via SSH
- Install n
- Make a custom directory
- Change the default prefix of Node.js version installs
- Install a version
- Test
- Alias the command
Step 1: Log Into Your Server
ssh pagelyuser@pagelyserver.vps.pagelyhosting.com
Step 2: Install n with NPM
npm install n
Step 3: Make the "n" Folder in Your Home Directory
mkdir ~/n
Step 4: Change Your N_PREFIX Environmental Variable
You will need to change the N_PREFIX environment variable so that the binaries are installed into your home directory. You can do this as follows:
export N_PREFIX=$HOME/n
Note: we suggest adding this to your ~/.bashrc or ~/.bash_aliases so that this change is loaded on login
Step 5: Add Your Node.js Version to the 'n' Directory
~/node_modules/n/bin/n 11.1.0
Step 6: Check the Version
~/n/bin/node --version
Step 7: Update the PATH Variable
export PATH="$HOME/n/bin:$PATH"
Note: We suggest adding this to your ~/.bashrc or ~/.bash_aliases so that this change is loaded on login. Below is an example of this, followed by a quick test:
echo 'export PATH="$HOME/n/bin:$PATH"' >> ~/.bash_aliases
For further instructions, please refer to the n documentation, or run the following help command:
n --help