Installing node LTS version on Ubuntu 14.04

warning

This post is more than 5 years old. While math doesn't age, code and operating systems do. Please use the code/ideas with caution and expect some issues due to the age of the content. I am keeping these posts up for archival purposes because I still find them useful for reference, even when they are out of date!

In a previous post, Installing Node.js and npm on Ubuntu 14.04 , I installed nodejs on Ubuntu 14.04 using what were current instructions at the time. Those notes are outdated at this point so I thought I'd document the current way to install the LTS version of node.

To install we will be following the (very brief) guide at debian node install -- this uses a simple curl/bash combination to setup a PPA for the LTS version of node (currently ver 4.4.0). Installation is as simple as:

$ curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
$ sudo apt-get install -y nodejs

This sets you up for automatic updates of the version 4.2+ LTS version of node-- an active LTS through April 2017, according to the node LTS schedule . Once the install is complete, you can find out versions of node and npm using:

$ node --version
v4.4.0
$ npm --version
2.14.20

Of course, your versions might be different if you install later.

sudo-free global installs

Note:

2016, July -- I'm adding this (I think) really important part to allow for npm install of packages without sudo -- this means it's in a non-destructive place that we have to setup. This approach is suggested by the (very nice) npm docs-- see here -- I'll be using "Option 2" described there.

To start, we make a directory to hold our global installs:

$ mkdir ~/.npm-global

Next, we tell npm about this new location:

$ npm config set prefix '~/.npm-global'

Finally, we have to update our path for bash. The npm docs suggest doing this in ~/.profile, but I will do this in ~/.bashrc (this is loaded by ~/.profile on Ubuntu machines). So, in ~/.bashrc add this line (at the end of the file is fine)

# add path for npm global installs
export PATH=~/.npm-global/bin:$PATH

I've added the comment so that I/we can remember what this is for (if it isn't obvious from the name). Finally, source ~/.bashrc like so

$ source ~/.bashrc

And we should be set; global install without sudo. If you'd like to test it out, install jshint globally with:

$ npm install -g jshint

You should see that it is using the new location. For example, you should get a similar result if you try whereis

$ whereis jshint
jshint: /home/cstrelioff/.npm-global/bin/jshint

Geting started

If you are new to nodejs -- I'm still pretty new -- you should look into

  • nodeschool is a place to learn about node, with local meetings that you can attend if you are lucky. I've been to the Oakland nodeschool and found it really useful.
  • Self-directed node lessons are available in the node workshopper list , starting with basic javascript and moving on to more advanced topics ranging from Reactjs to the Web Audio API. These are installed using npm and pretty easy to use. Also, these lessons form the basis for the nodeschool meetings, providing the basis for learning all things javascript and node.

That's it for this short post. Please leave comments if you have issues or other ideas on how to get started learning nodejs-- I'd love to see them!