Just like a majority of other open-source environment, Node.js has become quite a fast-evolving project. After almost every two weeks, there is some update or the other to boost both security and stability. The updates are not only limited to just one version branch; they are spread among all of them.
There are numerous methods one can use to update Node to the latest version on different operating systems. So, you’ll have no problems in getting the most recent Node.js version.
In the following article, we’ve mentioned the easiest yet the most effective methods of installing the newest Node version. We’ll be covering Linux, macOS, and Windows-based machines.
Before getting started, determine the Node.js version you have. You can do this by writing node -v
in the command prompt.
3 Methods of Updating Node.js on Linux Machines
We’ve listed the three common and most effective ways to update node on the Linux operating system. We recommend method one because of its simplicity. However, if you’re unable to go with the Node Version manager method, then you can update either via binary packages or package managers.
1. Use Node Version Manager
NVM (Node Version Manager), as mentioned earlier, is the best way to update Node. For this, you need a C++ compiler, the build-essential and libssl-dev packages. First, run an update to get the packages using these commands:
sudo apt-get update sudo apt-get install build-essential checkinstall libssl-dev
If you want to install or update Node version manager, get the install script with cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
First, close and open the terminal again. However, you can verify if the installation is successful by using the command -v nvm
. If everything worked, then the command will output nvm.
Once everything is set up, installing the updated Node version is hardly any difficulty. You can check the version of Node installed currently by typing nvm ls
. You can also see the version available to install with nvm by ls-remote
.
Now, download, compile, and then install the latest version of Node by typing nvm install #.#.#.
Remember, the # here will be replaced by the Node version you want. You can also inform nvm the version you want to use in each shell with nvm use #.#.#. Also, set up a default with an alias by nvm alias default node
.
2. Use Package Manager
The second best option after nvm is a package manager. NPM (node package manager) helps to discover, share as well as use code. It also allows users to manage dependencies. Node already comes installed with npm; however, the manager is updated more often than Node.
Check the version you have with npm -v. Then install the recent npm update by entering npm install [email protected] -g
. To ensure npm is updated correctly, run npm -v
.
You will also need npm’s n module to update Node. Run the following code to clear the cache and install n along with the latest Node version:
sudo npm cache clean -f sudo npm install -g n sudo n stable
Finally, use n latest to install the most recent release. You can also get a specific Node version by running n #.#.#
.
3. Use Binary Packages
Try your best to avoid this route. As a last resort, go to the official download page for Node.js. From here, get the 32-bit or the 64-bit Linux binary file. Here, you have two options. You can download the binary file from a browser. However, it is better to use the console. Remember, the Node version will change as more updates are released.
wget https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
You will also need xz-utils for unpacking the file. So, to install this, run the code sudo apt-get install xz-utlis
. Then, use the following code for installing the binary package in usr/local:
tar C /usr/local --strip-components 1 -xJf node-v6.9.2-linux.x64.tar.xz
Now, you have both Node as well as npm. So, for the next update, try the second method first.
Updating Node on Windows/MacOS Using Nodejs.org Installers
The download page on Node.js includes binary packages for both MacOS and Windows. However, there’s no need to make your life difficult. There are pre-made installers available to make the process easy: .msi for Windows and the .pkg for MacOS. These packages make installation efficient and simple to understand.
Simply download the file and run it and the installation wizard will handle the rest. With each update you download, the older versions of both npm and Node will be replaced by the newer ones.
FAQ Section
What Is the Node in Node JS?
Node.js is a platform that is built on Google Chrome’s JavaScript runtime. Its primary purpose is to build fast, scalable network applications easily. Node.js makes use of a non-blocking, event-driven model that makes it efficient and lightweight. Therefore, it is ideal for real-time data-intensive apps that work across different devices.
How Do I Check the Node JS Version?
To check the Node version installed in your computer, open a command-line tool. You can use Powershell, Command Prompt, or any other you prefer. After opening it, type node -v
. Doing so will print the version number like v0.10.35.
What Is Node JS Used For?
Primarily, Node.js is used for event-driven, non-blocking servers. This is because it has a single-threaded nature. It is also used for backend API services as well as traditional sites. However, it was designed using real-time and push-based architectures.
How Do You Update NPM?
If you’re using a Mac, then use the following code:
sudo npm install -g npm
You can update the outdated local packages as well by using npm update without a problem. Similarly, you can update the outdated global packages using npm update -g
.
The Final Word
So, now your Node update is done. In fact, updating both the npm and Node is just the starting. You’ll also have to update your other packages as well as dependencies. Doing so will maximize both security and compatibility so that you can enjoy using Node!