[node.js] Install Node.js on Ubuntu

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.

This question is related to node.js ubuntu npm

The answer is


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

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

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.


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

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

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)).


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


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


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

Really simple:

sudo apt install nodejs

And then type:

nodejs

to use it.


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

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/


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 and 14 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 which is currently tracking Node.js version 12 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 LTS Status  Codename  LTS Start     Maintenance Start   Maintenance End
 6.x    Active      Boron     2016-10-18    April 2018          April 2019
 7.x    No LTS
 8.x    Active      Carbon    2017-10-31    April 2019          December 2019
 9.x    No LTS
10.x    Active      Dubnium   October 2018  April 2020          April 2021
11.x    No LTS                2019-04-01    2019-06-30
12.x                          2019-10-22    2021-04-01          2022-04-01
13.x    No LTS                2020-04-20    2020-06-01
14.x    Current     Fermium   2020-10-20    2021-10-20          2023-04-30

As of today, you can simply install it with:

sudo apt-get install nodejs

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.


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

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

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

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?