Install Node.js on Ubuntu

node.jsUbuntuNpm

node.js Problem Overview


I'm trying install Node.js on Ubuntu 12.10 (Quantal Quetzal), but the terminal shows me an error about lost packages. I tried with this:

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

But when I came to the last line sudo apt-get install nodejs npm shows this error:

Failed to install some packages. This may mean that
you requested an impossible situation or if you are using the distribution
distribution that some required packages have not yet been created or been
been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nodejs: Conflicts: npm
E: Failed to correct problems, you have held broken packages.

Then I uninstalled the ppa:chris-lea/node.js and I was trying a second option:

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

The same error, the terminal says npm is the latest version, but it also shows me the text I shown in the top. I think the problem is ppa:chris-lea/node.js, but I don't know how solve it.

node.js Solutions


Solution 1 - node.js

Simply follow the instructions given here:

> Example install: > > sudo apt-get install python-software-properties python g++ make > sudo add-apt-repository ppa:chris-lea/node.js > sudo apt-get update > sudo apt-get install nodejs > > It installs current stable Node on the current stable Ubuntu. Quantal > (12.10) users may need to install the software-properties-common > package for the add-apt-repository command to work: sudo apt-get > install software-properties-common > > As of Node.js v0.10.0, the nodejs package from Chris Lea's repo > includes both npm and nodejs-dev.

Don't give sudo apt-get install nodejs npm. Just sudo apt-get install nodejs.

Solution 2 - node.js

As of today, you can simply install it with:

sudo apt-get install nodejs

Solution 3 - node.js

npm is automatically installed with Node.js in the latest version of Node.js. What do you see when you type node --version and npm --version in the terminal?

You can upgrade npm using npm itself as well:

[sudo] npm install -g npm

Solution 4 - node.js

My apt-get was old and busted, so I had to install from source. Here is what worked for me:

# Get the latest version from nodejs.org. At the time of this writing, it was 0.10.24
curl -o ~/node.tar.gz http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz
cd
tar -zxvf node.tar.gz
cd node-v0.6.18
./configure && make && sudo make install

These steps were mostly taken from joyent's installation wiki.

Solution 5 - node.js

This is the best way to easyly install Node.js. This also is actual for Ubuntu 12.04 (Precise Pangolin), Ubuntu 13.04 (Raring Ringtail), and Ubuntu 14.04 (Trusty Tahr).

Adding Node.js repositories
[sudo] apt-get install python-software-properties
[sudo] apt-add-repository ppa:chris-lea/node.js
[sudo] apt-get update
Node.js installation
[sudo] apt-get install nodejs
Now checking Node.js version
node -v

Outputs

v0.10.20
This command should install npm
npm install
Check npm version
npm -v

Outputs

1.4.3

If for some reason, if you see npm is not installed, you may try running:

[sudo] apt-get install npm

To update npm you may try running:

[sudo] npm install -g npm

Solution 6 - node.js

Now you can simply install with:

sudo apt-get install nodejs
sudo apt-get install npm

Make sure you have the Python and C interpreters/compilers preinstalled. If not, perform:

sudo apt-get install python g++ make

Solution 7 - node.js

You can use nvm to install Node.js. It allows you work with different versions without conflicts.

Solution 8 - node.js

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.19.0/install.sh | bash

nvm install v0.10.33

Just use nvm for Node.js version control - nvm.

Solution 9 - node.js

Just follow the official instructions from here to install on Ubuntu

Installation instructions

Node.js LTS (as of 01/2022 is v16.x):

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

Node.js Current (as of 01/2022 is v17.x):

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

Node.js v17.x:

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

Node.js v16.x:

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

Node.js v14.x:

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

Node.js v12.x:

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

Optional: install build tools

To compile and install native addons from npm you may also need to install build tools:

sudo apt-get install -y build-essential

Solution 10 - node.js

You can also compile it from source like this

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

Find detailed instructions here http://howtonode.org/how-to-install-nodejs

Solution 11 - node.js

sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

http://jstricks.com/install-node-js/

Solution 12 - node.js

Follow the instructions given here at NodeSource which is dedicated to creating a sustainable ecosystem for Node.js.

For Node.js >= 4.X

# 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

Solution 13 - node.js

Node.js is available as a snap package in all currently supported versions of Ubuntu. Specific to Node.js, developers can choose from one or more of the currently supported releases and get regular automatic updates directly from NodeSource. Node.js versions 6, 8, 9, 10, 11, 13, 14, 15, 16, 17 and 18 are currently available, with the Snap Store being updated within hours or minutes of a Node.js release.

Node.js can be installed with a single command, for example:

sudo snap install node --classic --channel 11/stable

The node snap can be accessed by the command node, for example:

$ node -v
v11.5.0

An up-to-date version of npm will installed as part of the node snap. npm should be run outside of the node repl, in your normal shell. After installing the node snap run the following command to enable npm update checking:

sudo chown -R $USER:$(id -gn $USER) /home/<b>your-username</b>/.config

Replace your-username in the above command with your own username. Then run npm -v to check if the version of npm is up-to-date. As an example I checked that npm was up-to-date, checked the version of an already installed package named yarn with the command npm list yarn and then updated the existing yarn package to the latest version with the command npm update yarn

Users can switch between versions of Node.js at any time without needing to involve additional tools like nvm (Node Version Manager), for example:

sudo snap refresh node --channel=11/stable

Users can test bleeding-edge versions of Node.js that can be installed from the latest edge channel by switching with:

sudo snap switch node --edge

This approach is only recommended for those users who are willing to participate in testing and bug reporting upstream.

Node.js LTS schedule
Release Status Codename Initial release LTS Start Maintenance Start Maintenance End
6.x EOL Boron 2016-04-26 2016-10-18 2018-04-30 2019-04-30
7.x EOL 2017-05-30 2017-06-30
8.x EOL Carbon 2016-10-25 2017-10-31 2019-01-01 2019-12-31
9.x EOL 2017-10-01 2018-06-30
10.x EOL Dubnium 2018-04-24 2018-10-30 2020-05-19 2021-04-30
11.x EOL 2018-10-23 2019-06-01
12.x Maintenance LTS Erbium 2019-04-23 2019-10-21 2020-11-301 2022-04-30
13.x EOL 2019-10-22 2020-06-01
14.x Maintenance LTS Fermium 2020-04-21 2020-10-27 2021-10-30 2023-04-30
16.x Active LTS Gallium 2021-04-20 2021-10-26 2022-10-18 2024-04-30
17.x Current 2021-10-19 2022-04-01 2022-06-01
18.x Current 2022-04-19 2022-10-25 2023-10-18 2025-04-30

Solution 14 - node.js

I personally do it this way:

sudo apt-get install python g++ make
wget http://nodejs.org/dist/node-latest.tar.gz
tar xvfvz node-latest.tar.gz
cd node-v0.12.0
./configure
make
sudo make install

If you want to install particular version then download the version you want from the Node.js site and execute the last tree steps.

I would strongly suggest not using the default Node.js package from the distribution market, because it would be probably outdated (i.e., the current for the time of writing this in the Ubuntu market is v0.10.25 which is too outdated compared to the latest (v0.12.0)).

Solution 15 - node.js

Here is the full description to create the first program using the express generator,

Ubuntu's package manager

To install Node.js and npm via apt-get, run these commands:

sudo apt-get update
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt-get install npm

Express application generator:

$ npm install express-generator -g

Display the command options with the -h option:

$ express -h

  Usage: express [options] [dir]

  Options:

    -h, --help          output usage information
    -V, --version       output the version number
    -e, --ejs           add ejs engine support (defaults to jade)
        --hbs           add handlebars engine support
    -H, --hogan         add hogan.js engine support
    -c, --css <engine>  add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git           add .gitignore
    -f, --force         force on non-empty directory

For example, the following creates an Express application named myapp in the current working directory:

$ express myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/public
   create : myapp/public/javascripts
   create : myapp/public/images
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css
   create : myapp/views
   create : myapp/views/index.jade
   create : myapp/views/layout.jade
   create : myapp/views/error.jade
   create : myapp/bin
   create : myapp/bin/www

Then install dependencies:

$ cd myapp
$ npm install

Run the app with this command:

$ DEBUG=myapp:* npm start

Then load http://localhost:3000/ in your browser to access the application.

The generated application has the following directory structure:

├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

7 directories, 9 files

Solution 16 - node.js

Install Node.js on Ubuntu 12.10 (Quantal Quetzal) or Ubuntu 14.04 LTS (Trusty Tahr) or Ubuntu 16.04.1 LTS (Xenial Xerus).

Please avoid installing Node.js with apt-get on Ubuntu. If you already installed Node.js with the built-in package manager, please remove that. (sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean)

The installation process on Linux is the same as on OS X. With the provided script:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash

$ nvm list
$ nvm ls-remote
$ nvm install 6.4.0
$ nvm use 6.4.0
$ nvm alias default 6.4.0
$ node -v
$ npm install -g npm
$ npm -v

Other issues while installing Node JS

Do not use sudo apt-get install nodejs npm. Always use sudo apt-get install nodejs

> And If you get the error sudo: add-apt-repository: command not found just run this command prior to the second one above: sudo apt-get install software-properties-common

> If sudo: add-apt-repository: command not found and needed to run sudo apt-get install python-software-properties before adding the repository

> try to use a bash -r if you had an old version before or node / npm does not appear in your console

> The linked instructions have been updated to curl -sL https://deb.nodesource.com/setup | sudo bash - sudo apt-get install -y nodejs


Edit Updated > For the latest version you can also use the URL nodejs.org/dist/node-latest.tar.gz

One more thing! Don’t forget to run the following command, which increases the amount of inotify watches.

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Solution 17 - node.js

Really simple:

sudo apt install nodejs

And then type:

nodejs

to use it.

Solution 18 - node.js

  1. sudo apt install nodejs
  2. sudo apt install npm
  3. curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  4. sudo apt-get install -y nodejs

Solution 19 - node.js

For the latest Node.js

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

sudo apt-get install nodejs
node -v
npm -v

Solution 20 - node.js

The Node.js package is available in the LTS release and the current release. It’s your choice to select which version you want to install on the system as per your requirements.

Use Current Release: At the last update of this tutorial, Node.js 13 is the current Node.js release available.

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

Use LTS Release: At the last update of this tutorial, Node.js 12.x is the LTS release available.

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

You can successfully add Node.js PPA to the Ubuntu system. Now execute the below command to install Node.js on and Ubuntu using apt-get. This will also install NPM with Node.js. This command also installs many other dependent packages on your system.

sudo apt-get install nodejs

After installing Node.js, verify and check the installed version. You can find more details about the current version on the Node.js official website.

node -v

v13.0.1

Also, check the npm version:

npm -v

6.12.0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavid AguilarView Question on Stackoverflow
Solution 1 - node.jsuser568109View Answer on Stackoverflow
Solution 2 - node.jsnixkuroiView Answer on Stackoverflow
Solution 3 - node.jsNoahView Answer on Stackoverflow
Solution 4 - node.jsynkrView Answer on Stackoverflow
Solution 5 - node.jsLifeInstructorView Answer on Stackoverflow
Solution 6 - node.jsBrijeshView Answer on Stackoverflow
Solution 7 - node.jsdemonodojoView Answer on Stackoverflow
Solution 8 - node.jsfeitView Answer on Stackoverflow
Solution 9 - node.jsJoão Pimentel FerreiraView Answer on Stackoverflow
Solution 10 - node.jsSajjad AshrafView Answer on Stackoverflow
Solution 11 - node.jsSadiView Answer on Stackoverflow
Solution 12 - node.jsVenkat KotraView Answer on Stackoverflow
Solution 13 - node.jskarelView Answer on Stackoverflow
Solution 14 - node.jsmagiccrafterView Answer on Stackoverflow
Solution 15 - node.jsoxygenView Answer on Stackoverflow
Solution 16 - node.jsGuptaView Answer on Stackoverflow
Solution 17 - node.jsAlonView Answer on Stackoverflow
Solution 18 - node.jskamalesh biswasView Answer on Stackoverflow
Solution 19 - node.jsRohit ParteView Answer on Stackoverflow
Solution 20 - node.jsSarthak DalabeheraView Answer on Stackoverflow