Installing a custom version of NVM and Node.js


This article walks you through installing Node.js using Node Version Manager (nvm) on a 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.


A VPS or Dedicated server. Node.js cannot be installed on a Shared server.

Can Node.js be used on shared servers?

No. DreamHost does not support Node.js on shared web servers, as the security setup on DreamHost shared servers is incompatible with compiling or running Node.js.

If you try to compile Node.js on one of the shared web servers, your user will automatically be banned through grsec (taking down all the PHP websites that run under that user) and the server will have to be rebooted before your user can be unbanned. If you do it one more time, you will be forced to move to a VPS.

Installing Node Version Manager (nvm)

The following steps install Node Version Manager. You can then use nvm to install Node.js.

  1. Check the version of Passenger running on your private server. The server must run version 4.0.37 or later.
    [server]$ dpkg -l | grep passenger
  2. Visit the following page to determine what version of NVM to install:
  3. Make sure you're in your user's directory.
    [server]$ cd ~
  4. Run the following command to download NVM. Change the version number as needed:
    [server]$ curl -o- | bash
    • This command installs NVM into a new directory under your user named /.nvm
    • This command also adds the following to your .bashrc file:
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
  5. 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.
    source ~/.bashrc
  6. Run the following command to allow your shell to use this new version of nvm:
    [server]$ . ~/.bash_profile
  7. To test if you can now use NVM, run the following which should respond with the version you have installed:
    [server]$ nvm --version

Installing Node.js

Now that nvm has been installed, you can use it to install Node.js

  1. Check which versions of Node.js are available:
    [server]$ nvm ls-remote
  2. Install any version of Node.js you wish:
    [server]$ nvm install 10.16.3
  3. Check which version of Node.js is running by entering the following:
    [server]$ node -v

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

Node Package Manager

At this point you have NVM and Node.js installed and active. Node Package Manager is also installed with Node.js. Visit the following page for further details on npm:

Check the version by running the following command:

[server]$ npm -v

To update npm to the latest version, run the following command:

[server]$ npm install npm@latest -g

Check the directory NPM writes to. Run the following command:

[server]$ npm config get prefix

If you installed NVM as shown above, you'll see the directory response as the /.nvm folder under your current user.

Installing packages

View the following page for instructions on how to install packages locally or globally:

Testing Node.js

Now that you have installed Node.js you can create a simple test script to confirm if it's functioning.

Simple 'Hello World!' script

Create and run this script within your terminal:

  1. Create a file named HelloWorld.js, and then add the following in the file:
    console.log('Hello World!');
  2. Run the following in your terminal to run the script:
    [server]$ node HelloWorld.js
    Hello World!

    If correctly installed you will see the console respond with Hello World!

Website example

You can also create a basic HTTP server to load a site.

  1. Create a file in your web directory titled server.js, and then add the following code in the file:
    var http = require("http");
    http.createServer(function(request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.write("Hello World");
    • This HTTP server will listen on port 8888.
  2. Start the server by running the following:
    [server]$ node server.js
  3. If you have enabled Node.js in the panel, you can just visit your site to see the file functioning. If you have not enabled Node.js in the panel, visit the page in a browser with port 8888 appended to the end. For example,

    If running correctly, your site will display the text Hello World!.


Passenger is not using your custom version of Node.js

If you find the custom version you installed is not being used, add the following code to an .htaccess file in your project's directory:

PassengerNodejs /home/username/.nvm/versions/node/v10.15.1/bin/node

Make sure to change the username and version to the version you have installed.

Next, reload Passenger my running the following command in the app's directory:

[server]$ mkdir tmp && touch restart.txt

In the future, you just need to touch the restart.txt file to restart the application.

[server]$ touch tmp/restart.txt

View the following page for further details:

Did this article answer your questions?

Article last updated PST.