This article walks you through installing Node.js using Node Version Manager (nvm) on a Shared, VPS or Dedicated server.
DreamHost support is unable to assist with custom installations. The directions below will explain how to install Node.js but if you find anything is not working as intended, you must contact a developer for further assistance.
What servers can Node.js be installed onto?
Node.js can be installed onto Shared, VPS, and Dedicated servers.
Is it possible to run Node.js on ports 80 or 443?
Yes, but only if you've enabled Passenger in the panel and the file to load your application is named app.js. View the following article for further details.
The version of Passenger running on Shared servers does not function with Node.js versions 14+. If you wish to use a more recent version, you would need to upgrade to a VPS.
Installing Node Version Manager (nvm)
The following steps install Node Version Manager. You can then use nvm to install Node.js.
- Visit the following page to determine what version of NVM to install:
- Make sure you're in your user's directory.
[server]$ cd ~
- Run the following command to download NVM. Change the version number as needed:
[server]$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
- This command installs NVM into a new directory under your user named /.nvm
- This command also adds the following to your .bashrc file:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
- If installing NVM as a user on a Shared or Dedicated machine, make sure the script isn't blocked by running the following as your user:
[server]$ setfattr -n user.pax.flags -v "mr" $NVM_DIR/nvm.sh
- View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. In this file, add the following line.
- Run the following command to allow your shell to use this new version of nvm:
[server]$ . ~/.bash_profile
- To test if you can now use NVM, run the following which should respond with the version you have installed:
[server]$ nvm --version 0.35.3
Now that nvm has been installed, you can use it to install Node.js
- Check which versions of Node.js are available:
[server]$ nvm ls-remote
- Install any version of Node.js you wish:
[server]$ nvm install v12.16.3
- If installing Nodejs as a user on a Shared or Dedicated machine, there may be an error that looks like this:
# # Fatal error in , line 0 # Check failed: reservation_.SetPermissions(protect_start, protect_size, permission). # # # #FailureMessage Object: 0x3dfe93bb400
[server]$ setfattr -n user.pax.flags -v "mr" $(find $NVM_DIR -type f -iname "node" -o -iname "npm" -o -iname "npx")
- Set your current version of node to your new version:
[server]$ nvm use v12.16.3 Now using node v12.16.3 (npm v6.14.4)
- Check which version of Node.js is running by entering the following:
[server]$ node -v v12.16.3
Setting the default version of Node.js
After installing a new version of Node.js, your current Shell session will use it. However, if you log out and log back in, it will revert to the default version. To set the new version as your default version, run the following command.
Make sure to change the version number to the version you've installed. This example uses v12.14.0.
[server]$ nvm alias default v12.14.0 default -> v12.14.0
Now that you have installed Node.js you can create a few simple test scripts to confirm if it's functioning.