Blog

Victor is a full stack software engineer who loves travelling and building things. Most recently created Ewolo, a cross-platform workout logger.

    Installing the latest Node.js on Ubuntu via nvm

    Here's a quick tutorial how to do a fresh install of the latest lts Node.js version on Ubuntu via Node version manager (nvm). This tutorial also covers removing any old Node.js installations. Installing via nvm is the recommended solution as you can manage different versions and root access is no longer required to install global node modules.

    Removing all old Node.js versions and modules

    Remove all node packages (note that npm should have automatically be removed but you can run the command just to be safe):

    sudo apt-get remove nodejs
    sudo apt-get remove npm
    

    Cleanup node modules:

    rm -rf ~/.npm
    sudo rm -rf /usr/local/lib/node_modules/
    
    You would now also need to delete any broken symlinks under /usr/local/bin/

    Remove any existing nvm installation:

    rm -rf ~/.nvm
    

    Install nvm

    Follow the installation instructions here: https://github.com/creationix/nvm

    Install the latest lts Node.js

    nvm help
    nvm install --lts
    nvm alias default node  # set the default version otherwise node is not available to a shell session
    
    node --version # v4.4.7
    npm --version # 2.15.8
    
    And voila, you have a freshly minted version of Node.js :). Read on for more info on installing global modules and some useful npm commands.

    Install global node modules

    I personally need the following packages installed globally as well:

    npm install -g grunt grunt-cli
    npm install -g gulp
    npm install -g mocha
    npm install -g browserify
    npm install -g envify
    
    npm install -g clean-css uglifyjs nodemon node-sass
    npm install -g forever
    

    Useful npm commands
    # List all installed packages
    npm ls -g
    
    # update a given package
    npm update -g mocha
    
    # find out all outdated packages
    npm outdated -g
    

    HackerNews submission / discussion

    Back to the article list.

    SmallData newsletter

    Subscribe to get articles as they are published direct to your inbox!