Install Node.js on Ubuntu, Linux, macOS, and Windows
Node.js installation sets up the node command that runs JavaScript files outside the browser. npm is usually installed along with Node.js, and it is used to install and manage JavaScript packages for Node.js projects.
In this tutorial, we shall learn how to install Node.js, set up the command-line environment, verify the installation, and run a simple .js file. The steps include the recommended download method, terminal-based installation notes, and a manual binary distribution method for Linux-based systems.
JavaScript programming language is used for Node.js application development. The source files of Node.js applications usually have the extension .js. Any text editor or code editor can be used to write Node.js code and save it as a JavaScript file.
To interpret the instructions written in the source .js files, Node.js runtime is required. You can install it from the official Node.js download page, through a package manager, or by extracting a binary distribution manually.
Download Node.js from the Official Node.js Website
For most beginners, the simplest method is to download Node.js from the official website at https://nodejs.org/en/download. Choose the installer or package for your operating system and processor architecture.
The official download page usually offers an LTS release and a Current release. For learning, development, and most production applications, the LTS version is generally the safer choice because it is maintained for a longer support period.
| Operating system | Common installation option | Notes |
| Windows | Windows installer | Installs Node.js and npm, and usually adds them to PATH automatically. |
| macOS | macOS installer or package manager | Useful for local development and command-line tools. |
| Ubuntu/Linux | Package manager, NodeSource, nvm, or binary archive | Use the method that matches your system administration preference. |
| Manual setup | Binary distribution archive | Useful when you need to install Node.js in a specific directory. |
Install Node.js in Terminal on Ubuntu or Linux
On Ubuntu and many Linux distributions, you can install Node.js using a package manager or a version manager. A version manager is helpful if you need to switch between multiple Node.js versions for different projects.
If your distribution repository provides a suitable version, you may install Node.js and npm with the package manager.
sudo apt update
sudo apt install nodejs npm
After installation, check whether the commands are available.
node -v
npm -v
The terminal should print version numbers for Node.js and npm. If your distribution provides an older Node.js version than your project needs, use the official Node.js downloads, NodeSource packages, or a version manager such as nvm.
Install Node.js on Windows
On Windows, download the installer from the official Node.js download page and run it. Keep the option that adds Node.js to PATH enabled, so that node and npm work from Command Prompt, PowerShell, or Windows Terminal.
After the installer completes, open a new terminal window and run the following commands.
node -v
npm -v
If both commands print version numbers, Node.js is installed correctly. If the command is not recognized, close the terminal and open it again. If the issue continues, check whether the Node.js installation directory has been added to the PATH environment variable.
Can Node.js Be Installed with npm?
npm is not used to install Node.js for the first time. npm is a package manager that is normally installed along with Node.js. First install Node.js using the official installer, a system package manager, or a version manager. After that, use npm to install packages inside Node.js projects.
For example, after Node.js is installed, you can use npm in a project folder like this:
npm init -y
npm install express
The first command creates a basic package.json file. The second command installs the Express package for that project.
Install Node.js binary distribution
The binary distribution method is useful when you want to install Node.js manually in a specific directory. The older example below uses a fixed Node.js archive name to explain the process. When you follow this method, replace the archive name with the file you downloaded from the official Node.js download page.
Download Node.js Binary Archive Manually
Download the latest suitable binary distribution from https://nodejs.org/en/download. Based on the operating system and architecture, download a suitable package. For Linux, this is commonly a .tar.xz or .tar.gz archive. For Windows, use the installer unless you specifically need a zip distribution.
Following are example package names from an older Node.js release. They are kept here only to show the naming pattern of binary packages.
| OS | Package |
| Linux | node-v8.4.0-linux-x64.tar.gz |
| MacOS | node-v8.4.0-darwin-x64.tar.gz |
| Windows | node-v8.4.0-win-x64.zip |
| SunOS | node-v8.4.0-sunos-x64.tar.gz |
Manual Node.js Binary Setup for Ubuntu, Linux, macOS, or SunOS
Once the download is complete, extract the package and include the Node.js bin directory in the system PATH variable. The following commands show the manual setup flow for a Linux x64 archive.
Go to the downloaded folder, open a Terminal from there, and execute the following commands. Replace the file name and folder name if they are different from what you downloaded.
Unzip the compressed package
~$ tar xvfz node-v8.4.0-linux-x64.tar.gz
Make nodejs directory in /usr/local/. Replace the file name, if it is different from what you have downloaded.
~$ sudo mkdir -p /usr/local/nodejs
Move the extracted nodejs package to /usr/local/nodejs/. Provide user password if asked.
~$ sudo mv node-v8.4.0-linux-x64/* /usr/local/nodejs/
Add the path /usr/local/nodejs/bin to PATH environment variable. Provide user password if asked.
Open .bashrc file and append the nodejs’ path at the end. To edit .bashrc, open a terminal and run the following command :
~$ sudo nano ~/.bashrc
Add the following line at the end of .bashrc file.
$ export PATH=$PATH:/usr/local/nodejs/bin
Once after adding the line, close the terminal and reopen again.
To verify if nodejs path has been added to PATH environment variable, run the following command :
~$ echo $PATH
For Linux or macOS, the value echoed back should include /usr/local/nodejs/bin if the manual PATH setup was successful.
For installing Node.js on Windows Operating System, double click on the .msi file and follow the prompt step by step. Finishing the prompt should install Node.js with PATH added to the environment variables.
Where Node.js Should Be Installed
There is no single required installation directory for every system. The correct location depends on the installation method.
- Official installer: use the default location suggested by the installer unless your organization has a specific policy.
- Linux package manager: let the package manager install Node.js in the standard system paths.
- nvm or another version manager: let the version manager store Node.js in the user’s home directory.
- Manual binary setup: use a directory such as
/usr/local/nodejsand add itsbinfolder to PATH.
For beginners, the official installer or a version manager is usually easier to maintain than manually moving binary files.
Verify Node.js installation
First verify the installed versions of Node.js and npm.
node -v
npm -v
Using a Text Editor, create a sample file with name verifyNode.js and copy paste the following content to that file.
verifyNode.js
console.log("Hi there! This is Node.js!")
And run the following command in Command prompt or Terminal from the directory of verifyNode.js script file.
Output
$ node verifyNode.js
Hi there! This is Node.js!
If the message is printed, Node.js is able to run JavaScript files from your terminal or command prompt.
Run Node.js File from the Command Line
Following is the syntax to run a Node.js file using node command line interface :
~$ node <file_name>
For example, if your file is named app.js, run:
node app.js
Node.js Installation FAQ
How do I install Node.js in terminal?
On Ubuntu or Debian-based Linux, you can use sudo apt install nodejs npm if the repository version is suitable. For newer or multiple versions, use the official Node.js downloads, NodeSource packages, or a version manager such as nvm.
Can I install Node.js with npm?
No. npm is normally installed with Node.js and is used after Node.js is available. Install Node.js first using an installer, package manager, or version manager. Then use npm to install packages for your projects.
How do I install Node.js on Windows?
Download the Windows installer from the official Node.js download page, run the installer, keep the PATH option enabled, and complete the setup. Then open a new terminal and run node -v and npm -v to verify the installation.
Where should Node.js be installed?
Use the default installer location on Windows or macOS unless you have a specific reason to change it. On Linux, let the package manager or version manager handle the location. For manual binary setup, a directory such as /usr/local/nodejs can be used with PATH configured correctly.
How do I check whether Node.js is installed correctly?
Run node -v and npm -v in a new terminal. Then create a small JavaScript file with console.log() and run it using node filename.js. If both version commands and the script run successfully, the installation is working.
Node.js Installation Editorial QA Checklist
- Does the tutorial direct users to the official Node.js download page instead of relying only on a stale release archive?
- Does the page clearly explain that npm is installed with Node.js and is not the normal first-time installer for Node.js itself?
- Are terminal commands separated from terminal output, and are new command examples marked with
language-bash? - Does the Windows section mention PATH verification with
node -vandnpm -v? - Does the manual binary installation section tell readers to replace old archive names with the package they actually downloaded?
Conclusion
In this Node.js Tutorial, we have learnt to install Node.js on a computer, check the node and npm commands, configure PATH for a manual binary installation, and verify the setup by executing a sample JavaScript .js file.
TutorialKart.com