General Guides

Search Knowledge Base by Keyword

How To Install Node.js On Linux

You are here:
Share:

Along with the many technologies out there, such as Ruby, Python and PHP, you may have heard of one called Node.js. Node.js is a lightweight and seemingly efficient JavaScript runtime that can be used to run JavaScript code outside of the browser. Among the other amazing features that Node.js has jam packed into itself, it is a popular choice for websites to use. Modern day, it is very simple and easy to setup though it can still be intimidating. Here we will show you how you can install Node.js and Node Package Manager (NPM) on your server.

 

How To Install Node.js On CentOS

This installation guide is going to rely on the curl command. If you do not have curl installed, you can type this in to your console:

Once that is installed, please proceed with the steps below.

  1. Connect to your VPS via SSH.
  2. Here we will want to add the Node.js repositories so that yum knows where to look for the latest Node.js when it is installing. To do this, you are going to want to type in the command:
  3. Once that is finished, you will now be able to install Node.js. To do this you are going to want to use this command:
  4. This will install Node.js onto your CentOS system. You will see periodic progress while this installs. It can usually take a few minutes to complete the installation. But it will let you know once it has completed.
  5. After the installation of Node.js has completed, it should have installed the Node Package Manager as well. To verify that both of these have been installed correctly, you can type these commands:

    For Checking Nodejs Installation:

    For Checking Node Package Manager Installation:

     


    If installation had completed successfully, you should see a version number listed. If you don’t see that, or you see an error message saying the command does not exist, it is likely the installation was unsuccessful.

 

How To Install Node.js On Debian

Before getting started with installing Node.js on Debian, you will want to make sure that you have the curl command installed before proceeding. For Debian, you can install this by typing the command:

 


After you have that installed, proceed with the steps below in getting Node.js and NPM installed on your server.

  1. Start by connecting to your Debian installation via SSH.
  2. Once connected, you’ll want to add the repositories so that Debian knows what you are referencing when you ask it to install Node.js. To do this, you can use the command:
  3. It might take a while for Debian to add that repository, however once done, you can proceed to install Node.js. For that, use the command:
  4. This can also take a little bit of time to install and setup on the system. Though once done, it will let you know. To verify that the installation has been completed successfully. Exactly as it was done in the steps for CentOS, you will want to check the version numbers. Type these commands to do that,

    For Checking Nodejs Installation:

    For Checking Node Package Manager Installation:

     


    If the installation was successfull, you should see a version number outputted when you type the command. If you don’t see that, or you see an error message saying the command does not exist, it is likely the installation was unsuccessful.

 

Quick Test To Make Sure Node.js Is Installed

Aside from the version testing in the guides above, you can also create a simple little Node.js document and run it to verify that everything is working correctly. To do this, there are a few steps involved which can be followed below.

  1. While logged into your server via SSH, create a file called test.js. This can be done simply with this command:
  2. After you have created that file, you will want to edit this file. In either operating system, there are various ways to do this. Here we will use the text editor nano in this guide which is a simple command line text editor. To use nano to edit your newly created file, type the command:
  3. That command will bring the console text editor up with that file open. Here is an example that we will use to test the Node.js installation:
  4. After you’ve typed all that out into the file, you can press Control + X at the same time to close the text editor, then press Y to save the file.
  5. Once you have saved the file, you can now execute the file by typing the following command:
    This should display something similar to “Web Server is running on 0.0.0.0:80“.
  6. Now if you navigate to your server’s IP address in your web browser, you should see the test site. If you are using a browser that is on the same server, you can just type in 127.0.0.1. Once you have verified that it looks good and shows up, you can close the Web server on your server by pressing Control + C at the same time to force close the program.

 

If you should have any questions or would like assistance, do feel free to contact us through Live Chat, on our Phones, or by submitting a ticket with our Technical Support team.


Share: