I’m working on an API written in Node.js v6.4.0. When trying to deploy it to my Ubuntu 16.04 server, however, I’m running into a compatibility problem. See, when I setup my server, I installed the latest version of Node (currently v6.6.0), which means that the Node version is different on my server than it is on my MacBook.
This is no longer the recommended way to install different versions of Node.js. Instead, use NVM.
When installing Node, you don’t have a lot of options. Or, at least, I didn’t think so. I followed the instructions on their website, and that only gives me the latest version (which I didn’t want). After hours of frustration, I finally figured out how to install a specific version of Node. Let me explain.
Note that I’m installing this on Ubuntu 16.04, so don’t blindly copy and paste the following commands unless you know they will work for you.
The Node.js website has a handy directory of versions and install files. It lists all versions of Node formatted as “vX.X.X”. For me, I was looking for Node v6.4.0. So I clicked on the version I wanted. Clicking on “v6.4.0”, I then saw a list of installation files. I was on a 64-bit Linux server, so the file I was looking for was
node-v6.4.0-linux-x64.tar.gz. Now that I’ve found the file I want, I could download it onto the server and install it.
Downloading the file
First, I moved to a directory I was comfortable downloading a temporary file to (i.e.
~/tmp, etc.). Once there, I entered:
replacing the “X.X.X” with the version I wanted. In my case:
That downloaded the file to my current directory, so if I listed all the files and folders with ls, I would see a file called
node-v6.4.0-linux-x64.tar.gz. Next I installed it.
Now that I had the file, I could install Node. The following command will install the Node binary package to
sudo tar -C /usr/local --strip-components 1 -xzf node-v6.4.0-linux-x64.tar.gz
And that’s it! Next I ran
to see that v6.4.0 was successfully installed. To be sure, I also ran
to verify that npm was also installed.
For the neckbeards out there, I know, this is like 4th grade math. But hopefully at least one Googler will learn something from this.
Recommended reading: Scaling a Node.js API With Google App Engine