Questions tagged [nodejs]

Event-driven I/O server-side JavaScript environment based on V8. Includes API documentation, change-log, examples and announcements.

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.1

Installation

Node.js may be installed via three major methods on Ubuntu and its official derivatives.

Via APT

The first method is via APT (or by the front-end, the Ubuntu Software Center) by running:

sudo apt-get install nodejs

the problem, however, is that Node.js installed this way is usually very out of date.

Via APT, cURL and nodesource

Alternately, Node.js may be installed via running:

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

The version provided via this method is usually up to date and even when it is not it is usually only out of date by at most a few days. This installation will be automatically updated whenever one runs Software Updater.

From source

If one requires the very latest version, or another version that is not available by either of these two methods one can install from source code. This is usually the most time-consuming of methods, potentially taking over an hour, depending on one's platform, although most of this is automated requiring very little user input. To get the source code one can go to http://nodejs.org/dist/, to find a URL for the release they want (which is http://nodejs.org/dist/latest/node-$ver.tar.gz for the latest release, where $ver is replaced with the latest available version with the letter v in front of it, for example, $ver=v0.12.7 for version 0.12.7). One can then download this release from one's web browser, via , via or via whatever download manager one would prefer. For simplicity's sake the next code assumes one is downloading the tarball for Node.js version 0.5.1+ via wget, in which case the code is (run from the directory to which you want the source code downloaded):

#Install the dependencies; if you are installing Node.js 0.6.x you will also
#need libssl-dev
sudo apt-get install build-essential python
#Setting the version one is installing, remember the v!
ver=v0.12.7
wget -c http://nodejs.org/dist/$ver/node-$ver.tar.gz
tar -xzf node-$ver.tar.gz
cd node-$ver
./configure
make
sudo make install

note that at the tar line one can specify where the source code is extracted to if one wishes (via adding -C DESTDIR where DESTDIR is the destination of the source code), but if one does one will need to adjust the next line to cd DESTDIR. This installation may be more flexible than the previously-outlined methods but it will not automatically update itself. Instead to update a source installation one will need to re-run lines 5-10 with the updated ver value.

If one anticipates updating Node.js manually often (e.g., if one wants the latest release of Node.js as soon as it is released) it may be best to use instead to get the source code. Although this method will take up more hard disk drive (HDD) space and is a larger download (>100 MB), hence it is only recommended for those planning to update their Node.js installation regularly.

To get the source code via git and then install it run:

sudo apt-get install git #Installing git
git clone https://github.com/joyent/node.git
cd node
git remote add upstream https://github.com/joyent/node.git
#Again, replace this with the latest available release
ver=v0.12.7
git fetch upstream
git checkout $ver
./configure
make
sudo make install

then to update this installation re-run the last 6 lines (from ver=v0.12.7 down) of this code, with an updated ver value.

References

  1. nodejs.org
600 questions
29
votes
2 answers

How can I install a tar.xz file from nodejs.org?

I'm a novice with Ubuntu. I downloaded nodejs from the nodejs.org website. The file I downloaded is node-v7.1.0-linux-x64.tar.xz I know how to extract it, but that's it. Please explain how I can install it, and where I should put it in the…
28
votes
6 answers

How to update Node.js to the long term support version on Ubuntu 20.04?

I'm pretty new to Ubuntu. I could install Node.js to the latest version 14.7.0 but the program I'm using (Jhipster) tells me that I need to install the Long Term Support (LTS, currently 12.18.3) and do not have any idea about how to do it. There is…
Mike
  • 393
27
votes
7 answers

Checking version of nodejs returns nothing

I'm trying to install node js onto Ubuntu so that I can run AngularJS. I'm not sure if I've installed it before so I ran sudo-apt get install node and once that is done I then run node --version but nothing is returned on my terminal. jason@jason:~$…
thank_you
  • 667
27
votes
4 answers

NPM is incorrect version on latest Ubuntu (18.04) installation

Normal installation would be sudo apt install nodejs to install Node.js and then sudo apt install npm to install Node Package Manager. However, upon doing so, npm -v says 3.5.2 . To upgrade normally, I would do sudo npm install -g npm , which…
25
votes
3 answers

node & nodejs have different version

I successfully update/install the latest version of node js by using those commands (the official curl way not working for me) : sudo npm cache clean -f sudo npm install -g n sudo n stable sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node…
24
votes
2 answers

Installing the latest Node.js / MongoDB?

How can I install Node.js and MongoDB so they are the most current versions? The available versions from package manager are not up to date, and PPA from Chris Lea for Node.js doesn't get updated on a regular basis.
22
votes
7 answers

Having trouble to find the node in ubuntu 14.04 after installing

I installed the NodeJS in Ubuntu 14.04 by nvm by following this site Installing NodeJS Though I had the following problem as nvm ls sbin mkdir: cannot create directory ‘/usr/sbin/alias’: Permission denied Then I found to resolve this as (from NVM…
lara
  • 397
20
votes
4 answers

Install Node.js in Ubuntu 14.04

I installed Node.js with: sudo apt-get install nodejs But when I type in a console node I get nothing, no command not found , no any error. But when I type nodejs I get the Node.js prompt > . Now, I can't install anything with npm , I tried to…
Gocht
  • 385
20
votes
3 answers

npm does not support Node.js v10.19.0

npm does not support Node.js v10.19.0 You should probably upgrade to a newer version of node as we can't make any promises that npm will work with this version. You can find the latest version at https://nodejs.org/
JoKalliauer
  • 1,704
  • 2
  • 21
  • 29
19
votes
3 answers

How to install Node JS latest version on Ubuntu 22.04?

Now, the latest version of Node is 20.11.0 . However, every time I tried to install Node, it installed the 12.22.9 version. This commands is not working, every time it installed the same version 12.22.9 curl -sL https://deb.nodesource.com/setup_10.x…
19
votes
1 answer

Why does NPM install so many packages?

When deploying Node and NPM on Ubuntu 20.04 I noticed that when you run sudo apt install npm it details a massive number of dependencies that it want's to install with it. Why is this? Surely it doesn't require all these packages to run the package…
18
votes
2 answers

Systemd service start results in error of code=exited, status=200/CHDIR

I'm trying to automatically run the following command on system boot with systemd. /usr/bin/node /var/www/html/rest-api/dist/index.js I have verified the command works by running it manually but when I try to initiate it with a rest.service file I'm…
doovers
  • 283
17
votes
3 answers

How to remove nodejs from nodesource.com?

I have installed nodejs from nodesource.com: curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash - sudo apt-get install nodejs It installed nodejs 0.12.4 , but how can i remove it now including all footprints from that repo? I can see a file…
17
votes
1 answer

How to remove npm and reinstall npm completely in 18.04?

I was using ubuntu16.04 upgraded to ubuntu 18.04. followed some tutorial to remove npm, but now stuck. I have: ~$ npm list -g bash: /usr/bin/npm: No such file or directory and: sudo apt-get install npm Reading package lists... Done Building…
Aipo
  • 365
16
votes
3 answers

pipe to sudo -E bash -

I was wondering what is the purpose of piping the downloaded file by curl into sudo -E bash - in the following shell: curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
youssef
  • 353
1
2
3
…
39 40