Ubuntu: How can I update my nodeJS to the latest version?



Question:

I have installed nodeJS on Ubuntu with following code

sudo apt-get install nodejs  

Since I am a new user for ubuntu I also ran this code too

sudo apt-get install npm  

Now when I type

 nodejs --version  

It shows

v0.6.19  

I checked and saw latest nodeJS version is 0.10.26

How can I update my version of nodeJS to 0.10.26?

I tried with

 sudo apt-get install <packagename>   sudo apt-get install --only-upgrade <packagename>  

but no luck.


Solution:1

Use n module from npm in order to upgrade node

sudo npm cache clean -f  sudo npm install -g n  sudo n stable    sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs  

(NOTICE that the default installation for nodejs is in the /usr/bin/nodejs and not /usr/bin/node)

To upgrade to latest version (and not current stable) version, you can use

sudo n latest  

To undo:

sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node  sudo n rm 6.0.0     # replace number with version of Node that was installed  sudo npm uninstall -g n  

Found in David Walsh blog http://davidwalsh.name/upgrade-nodejs


Solution:2

Complete installation instructions have since been uploaded here by Nodesource. It is copied below for your reference. Instructions are the same for updating to the latest version.

Node.js v8.x:

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_8.x | bash -  apt-get install -y nodejs  

Node.js v7.x:

NOTE: Debian Wheezy and Ubuntu Precise packages are NOT available for this release. Please reference running Node.js >= 4.x on older distros

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_7.x | bash -  apt-get install -y nodejs  

Node.js v6.x:

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_6.x | bash -  apt-get install -y nodejs  

Node.js v5.x:

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_5.x | bash -  apt-get install -y nodejs  

Node.js v4.x:

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 4.x on older distros.

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_4.x | bash -  apt-get install -y nodejs  

Node.js v0.12:

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_0.12 | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_0.12 | bash -  apt-get install -y nodejs  

Node.js v0.10:

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_0.10 | sudo -E bash -  sudo apt-get install -y nodejs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_0.10 | bash -  apt-get install -y nodejs  

io.js v3.x:

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_iojs_3.x | sudo -E bash -  sudo apt-get install -y iojs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_iojs_3.x | bash -  apt-get install -y iojs  

io.js v2.x:

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_iojs_2.x | sudo -E bash -  sudo apt-get install -y iojs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_iojs_2.x | bash -  apt-get install -y iojs  

io.js v1.x:

Note: this branch of io.js is not actively maintained and is not recommended for production use.

# Using Ubuntu  curl -sL https://deb.nodesource.com/setup_iojs_1.x | sudo -E bash -  sudo apt-get install -y iojs    # Using Debian, as root  curl -sL https://deb.nodesource.com/setup_iojs_1.x | bash -  apt-get install -y iojs  


Solution:3

This PPA is out of date and not maintained anymore; you should consider other answers instead of this one.

You can install the latest version from PPA:

sudo add-apt-repository ppa:chris-lea/node.js    sudo apt-get update    sudo apt-get install nodejs  


Solution:4

I use NVM to handle my Node versions. Very simple to set up and easy to use.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash  export NVM_DIR="$HOME/.nvm"  [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm  

To install NVM globally instead, use the following curl command instead of the one above (and presumably don't use the second command but do use the third one)

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | NVM_DIR=/usr/local/nvm bash  

Then use nvm install stable (or insert a version number instead of stable) to get the latest/a specific version of Node. Use nvm use stable (or a specific version number) to use that Node version. Use nvm ls to see what Node versions you have installed and nvm uninstall stable(or a specific version number) to remove a specific version of Node.

Sources: Install, usage


Solution:5

I tried the same list commands on my ubuntu 14.04 but it was still throwing an error.

Commands I executed were:

sudo add-apt-repository ppa:chris-lea/node.js    sudo apt-get update    sudo apt-get install nodejs  

and the error i was getting:

Invalid version 0.12.2  Line 299: curl not found in /bin/n  

What I figured out was curl utility was not installed on my os.

I executed command:

apt-get install curl  

(use sudo as prefix if you are not su)

and then repeated the steps suggest in answer and it work ;)


Solution:6

This one installs the latest node v0.12.* from nodesource.

sudo apt-get install -y curl  curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -  sudo apt-get install -y nodejs  

For node v4.x

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »