Install the latest versions of Node.js and npm, into a Docker container, with or without the need for root access. Easily update both applications to the latest versions.
Ubuntu and Node
Recently, I was setting up a new development laptop with Ubuntu 14.10 (Utopic Unicorn). As part of the setup, I needed to install all the several development tools, including Node.js and npm. Researching the current recommendations for installing Node.js and npm on Ubuntu, I found using the traditional ‘apt-get‘ command does not always install the latest versions of either application. Additionally, ‘apt-get’ makes updating those versions difficult.
After a lot of investigation, I created three different snippets of code to install the latest copies of Node.js and npm. Some of my code came from Isaac Z. Schlueter‘s series of installations Gists, and a post on StackOverflow by Pascal Hartig. Joyant and others recommended Isaac’s Gists for installing earlier versions of Node.js and npm. Other code was found in posts by DigitalOcean. Versions are as follows:
- Version 1: using ‘apt-get install’
- Version 2: using curl, make, and npmjs.org’s install script
- Version 3: version 2 without requiring ‘sudo’ to use npm*
*There is some debate on the use of ‘sudo’ with some earlier versions of npm. It appears not to be recommended with the latest versions of npm.
Docker containers and virtual machines (VM) are ideal platforms for developing and testing applications, locally. I often create a Docker container or VirtualBox VM, to install and test new scripts, before running them within our software environments. To test this code, I created three separate Docker containers, based on the official 14.04 Ubuntu base image, located on Docker Hub. I then executed each version of code within a container. After installation testing, I chose version 2 for my laptop.
The three versions of install scripts on gist.github.com, perform the following tasks:
- Creates Docker container
- Updates Ubuntu system packages within container
- Creates new ‘testuser’ account within container (‘testuser’)
- Installs required software to install Node.js, if necessary (curl, make, etc.)
- Installs Node.js and npm
- Verifies installation locations and contents correct
- Click to share on Twitter (Opens in new window)
- Click to share on Google+ (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to email this to a friend (Opens in new window)
- Click to print (Opens in new window)
This entry was posted on November 17, 2014, 10:51 pm and is filed under Bash Scripting, Build Automation, Client-Side Development, DevOps, Enterprise Software Development. You can follow any responses to this entry through RSS 2.0. You can leave a response, or trackback from your own site.