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.
Use n module from npm in order to upgrade node
To upgrade to latest version (and not current stable) version, you can use
Fix PATH:
To undo:
You may need to restart your terminal to see the updated node version.
Found in David Walsh blog
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.
If you don't like
curl ... | sudo bash -
then you can follow the manual instructions, which tells you how to add the Node.js repository to/etc/apt/sources.list.d/
yourself.NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros
Node.js Current:
Node.js v13.x:
Node.js v12.x:
Node.js v11.x:
Node.js v10.x:
Node.js v9.x:
Node.js v8.x:
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
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.
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.
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.
Node.js v0.12:
Node.js v0.10:
io.js v3.x:
io.js v2.x:
io.js v1.x:
Note: this branch of io.js is not actively maintained and is not recommended for production use.
I also recommend using nvm instead, and also removing the already installed version to avoid conflicts in the terminal
then install nvm and use it
Video Explanation
to download and install nvm
should download and install the latest version of node.
To update node later on just do
You can install the latest version from PPA:
I use NVM to handle my Node versions. Very simple to set up and easy to use.
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)
Then use
nvm install stable
(or insert a version number instead ofstable
) to get the latest/a specific version of Node. Usenvm use stable
(or a specific version number) to use that Node version. Usenvm ls
to see what Node versions you have installed andnvm uninstall stable
(or a specific version number) to remove a specific version of Node.Sources: Install, usage
Note
If you are struggling with updating
npm
to the latest stable version because you are stuck at a specific version ofnpm
and every time you update it that doesn't work then you can use this method to updatenpm
as well. As soon as you install the latest stable version ofnode
,npm
will automatically be updated to its latest stable version.NVM (Node Version manager) with
--lts
NVM was mentioned at: https://askubuntu.com/a/441527/52975 but here goes a more complete usage example, including the sane
--lts
version, which installs the latest Long Term Support version of Node, which is likely the one you want if you don't have more specific requirement.Install NVM and the latest Node LTS version:
Now test it out with a dummy package:
Since the sourcing has to be done for every new shell, the install script hacks adds some auto sourcing to the end of your
.barshrc
. That works, but I prefer to remove the auto-added one and add my own:Advantages:
allows you to use multiple versions of Node and without sudo
is analogous to Ruby RVM and Python Virtualenv, widely considered best practice in Ruby and Python communities
downloads a pre-compiled binary where possible, and if not it downloads the source and compiles one for you
We can easily switch node versions with:
You can then use a git tracked
.nvmrc
file to indicate the node version required for a given project: https://stackoverflow.com/questions/24869959/how-do-i-specify-a-local-version-of-node-for-a-project/54503474#54503474With this setup, you get for example:
gives:
and:
gives:
and if we want to use the globally installed module:
gives:
so we see that everything is completely contained inside the specific node version.
Tested in Ubuntu 17.10.
CLEAN SIMPLE STEPS (which I use) :
Uninstall previous version of node -
sudo apt remove node && sudo apt autoremove
Go to https://nodejs.org/en/ and download the latest version of node.
Now open the terminal and change the directory where node is downloaded and then run-
tar -xvf node-v12.16.2-linux-x64.tar.xz
now run this in terminal -
nano ~/.bashrc
and append it with the following –
export PATH=/path/to/node-js/bin:$PATH
Where, /path/to/node-js/ is to be replaced where you extracted node in step 3.`
run a last command
source ~/.bashrc
That's it.
Now you can check your node version by
node -v
I tried the same list commands on my ubuntu 14.04 but it was still throwing an error.
Commands I executed were:
and the error i was getting:
What I figured out was curl utility was not installed on my os.
I executed command:
(use
sudo
as prefix if you are notsu
)and then repeated the steps suggest in answer and it work ;)
This one installs the latest node v0.12.* from nodesource.
For node v4.x
If using
n
does not work, you can install the latest version ofnodejs
(i. e. version 8) running the following commands:Further instructions are here.