Cannot install packages using node package manager in Ubuntu - node.js

NodeJS interpreter name(node) on Ubuntu has been renamed to nodejs because of a name conflict with another package. Here's what the readme. Debian says:
The upstream name for the Node.js interpreter command is "node".
In Debian the interpreter command has been changed to "nodejs".
This was done to prevent a namespace collision: other commands use
the same name in their upstream, such as ax25-node from the "node"
package.
Scripts calling Node.js as a shell command must be changed to instead
use the "nodejs" command.
However, using nodejs mucks up installing packages using npm. Package installation fails with the following error:
sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read /usr/share/doc/nodejs/README.Debian
How do I make npm understand that nodejs is already installed on the system but the interpreter name is different?

TL;DR:
sudo apt-get install nodejs-legacy
First of all let me clarify the situation a bit. In summer 2012 Debian maintainers decided to rename Node.js executable to prevent some kind of namespace collision with another package. It was very hard decision for Debian Technical Committee, because it breaks backward compatibility.
The following is a quote from Committee resolution draft, published in Debian mailing list:
The nodejs package shall be changed to provide /usr/bin/nodejs, not /usr/bin/node. The package should declare a Breaks: relationship with
any packages in Debian that reference /usr/bin/node.
The nodejs source package shall also provide a nodejs-legacy binary package at Priority: extra that contains /usr/bin/node as a symlink to
/usr/bin/nodejs. No package in the archive may depend on or recommend
the nodejs-legacy package, which is provided solely for upstream
compatibility. This package declares shall also declare a Conflicts:
relationship with the node package.
<...>
Paragraph 2 is the actual solution for OP's issue. OP should try to install this package instead of doing symlink by hand. Here is a link to this package in Debian package index website.
It can be installed using sudo apt-get install nodejs-legacy.
I have not found any information about adopting the whole thing by NPM developers, but I think npm package will be fixed on some point and nodejs-legacy become really legacy.

Try linking node to nodejs. First find out where nodejs is
whereis nodejs
Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.

You can also install Nodejs using NVM or Nodejs Version Manager There are a lot of benefits to using a version manager. One of them being you don't have to worry about this issue.
Instructions:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download and install it with the following syntax:
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
This will download the script and run it. It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.
To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:
source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
. . .
v0.11.10
v0.11.11
v0.11.12
v0.11.13
v0.11.14
As you can see, the newest version at the time of this writing is v0.11.14. You can install that by typing:
nvm install 0.11.14
Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 0.11.14
When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v
The comeplete tutorial can be found here

Install nvm first using:
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
Run command
source ~/.profile
Now run this and this will show will all installed or other versions of packages:
nvm ls-remote
Installed packages will be in green. Install whatever version you want:
nvm install 6.0.0
Check where is not installed:
which node
Check current version:
node -v
n=$(which node);
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local

sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs-legacy
source ~/.profile
Combined the accepted answer with source ~/.profile from the comment that has been folded and some clean up commands before. Most likely you will also need to sudo apt-get install npm after.

for me problem was solved by,
sudo apt-get remove node
sudo apt-get remove nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
alias node=nodejs
rm -r /usr/local/lib/python2.7/dist-packages/localstack/node_modules
npm install -g npm#latest || sudo npm install -g npm#latest

Here's another approach I use since I like n for easy switching between node versions.
On a new Ubuntu system, first install the 'system' node:
curl -sL https://deb.nodesource.com/setup | sudo bash -
Then install n module globally:
npm install -g n
Since the system node was installed first (above), the alternatives system can be used to cleanly point to the node provided by n. First make sure the alternatives system has nothing for node:
update-alternatives --remove-all node
Then add the node provided by n:
update-alternatives --install /usr/bin/node node /usr/local/bin/node 1
Next add node provided by the system (the one that was installed with curl):
update-alternatives --install /usr/bin/node node /usr/bin/nodejs 2
Now select the node provided by n using the interactive menu (select /usr/local/bin/node from the menu presented by the following command):
update-alternatives --config node
Finally, since /usr/local/bin usually has a higher precedence in PATH than /usr/bin, the following alias must be created (enter in your .bashrc or .zshrc) if the alternatives system node is to be effective; otherwise the node installed with n in /usr/local/bin takes always precedence:
alias node='/usr/bin/node'
Now you can easily switch between node versions with n <desired node version number>.

On Linux Mint 17, I tried both solutions (creating a symlink or using the nodejs-legacy package) without success.
The only thing that finally worked for me was using the ppa from Chris Lea:
sudo apt-get purge node-*
sudo apt-get autoremove
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
This installed node version 10.37 and npm 1.4.28. After that, I could install packages globally.

As other folks already mention, I will suggest not to use "sudo apt-get" to install node or any development library. You can download required version from https://nodejs.org/dist/v6.9.2/ and setup you own environment.
I will recommend tools like nvm and n, to manage you node version. It is very convenient to switch and work with these modules.
https://github.com/creationix/nvm
https://github.com/tj/n
Or write basic bash to download zip/tar, extract move folder and create a soft link. Whenever you need to update, just point the old soft link to new downloaded version.
Like I have created for my own, you can refer:
https://github.com/deepakshrma/NodeJs-4.0-Reference-Guide/blob/master/nodejs-installer.sh
#Go to home
cd ~
#run command
#New Script
wget https://raw.githubusercontent.com/deepakshrma/NodeJs-4.0-Reference-Guide/master/nodejs-installer.sh
bash nodejs-installer.sh -v lts
#here -v or --version can be sepecific to 0.10.37 or it could be latest/lts
#Examples
bash nodejs-installer.sh -v lts
bash nodejs-installer.sh -v latest
bash nodejs-installer.sh -v 4.4.2

Simple solution from here
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash --
sudo apt-get install nodejs
You can specify version by changing setup_x.x value, for example to setup_5.x

Your System is not able to detect the path node js binary.
1.which node
2.Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.

Uninstall whatever node version you have
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
install nvm (Node Version Manager) https://github.com/creationix/nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Now you can install whatever version of node you want and switch between the versions.

I fixed it unlinking /usr/sbin/node (which is linked to ax25-node package), then I have create a link to nodejs using this on command line
sudo ln -s /usr/bin/nodejs /usr/bin/node
Because package such as karma doesn't work with nodejs name, however changing the first line of karma script from node to nodejs, but I prefer resolve this issue once and for all

For me the fix was removing the node* packages and also the npm packages.
Then a fresh install as:
sudo apt-get install autoclean
sudo apt-get install nodejs-legacy
npm install

Problem is not in installer
replace nodejs with node or change the path from /usr/bin/nodejs to /usr/bin/node

This is the your node is not properly install, first you need to uninstall the node then install again.
To install the node this may help you
http://array151.com/blog/nodejs-tutorial-and-set-up/
after that you can install the packages easily. To install the packages this may help you
http://array151.com/blog/npm-node-package-manager/

you can create a link ln -s nodejs node in /usr/bin
hope this solves your problem.

node -v // first check it's install or not
npm -v
sudo apt install npm
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
sudo apt-get install nodejs
then check
node -v or node –version
npm -v or npm –version
or you can remove package.lock json file / node_modules than run npm i
I hope it'll work fine
steps : https://www.geeksforgeeks.org/installation-of-node-js-on-linux/

Faced same issue, steps below worked for me.
Install curl on your system then run NVM installer script.
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Load the environment
source ~/.profile
Install the supported version of Node.js.
nvm install 16.15.1
Confirm the installation
node -v

Related

Node versions do not match: node vs. sudo node -v ... WSL2 Ubuntu 22.04.1

As you can see in the image below, I see two different versions of node depending on which command I run.
I need the newer version, but npm sees the old version.
Many times I've removed, purged, reinstalled, etc.
I tried installing nvm as root and setting the node version there, but that didn't help either.
If I use apt install nodejs instead of nvm, it tells me that I already have the newest version, which it believes is 12.22.9.
How do I get npm to recognize the newer version (18.12.1) of node that I installed via nvm?
It is because you have a different version of the Node.js which is installed for the root and that particular user.
First, you need to uninstall Node.js:
sudo apt-get remove nodejs
or
sudo npm rm npm -g
If you have any problem with the above commands, then after running which node command, go to that directory, and run the following commands:
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Do the same thing for the current user if needed.
The default Ubuntu/Debian package manager does not have the latest Node.js, and that's why whenever you try to install Node.js with apt install nodejs it says you have the latest version.
According to the official Node.js documentation, for installing the latest version, you should follow these steps:
Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs
P.S: No need to run npm or node with sudo. Therefore, I highly recommend you to not use every command with sudo.

How to install latest node version on Ubuntu?

I want to install the latest node (v6.2.0 at the time of writing) on Ubuntu. But as I do
sudo apt-get nodejs
This installed v0.10.37.
Can you please help me in installing the latest version of node js and also npm latest version?
This is very simple,
Grab the Linux node distribution from here:
https://nodejs.org/dist/v6.2.0/
Open Terminal and type below command:
sudo tar -C /usr/local --strip-components 1 -xzf ~/Downloads/node-v6.2.0-linux-x64.tar.gz
ls -l /usr/local/bin/node
That`s it.
Now check your node version by typing:
node -v
npm -v
One can install any version of node in Ubuntu using above steps.
There is official instruction:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Follow https://deb.nodesource.com/setup_6.x to read shell script before execute above commands.
You always must to know what you run, especially by sudo.
Any version of node install is very easy
Just click Node.js scroll down and go Installation instructions and chose which version you want to install
To Install 12.x version of node:
Open your terminal [Ctrl+Alt+t]
execute below command
Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
or
Using Debian, as root
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
To remove previous version use command
sudo npm cache clean -f
sudo npm install -g n
and then for latest version
sudo n latest
Or for stable version
sudo n stable
By far the most convenient way to install and manage node versions on your machine is the Node Version Manager a.k.a nvm. Just follow the installation instructions in the repo and after you have it installed run
nvm install 6.2.0
I would suggest installing through package manager to make sure it installs with accurate dependencies.
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
Also, use NPM
sudo apt-get install npm
to install modules, like so:
npm install express
Install the package through the official download page, in a .deb format. Go ahead and grab the newest version here:
https://nodejs.org/download/release/latest/
Just go ahead and download your desired version and double-click on the downloaded .deb file, and you're good to go. npm comes with nodejs, btw.
RECOMMENDED READING
https://www.npmjs.com/package/npm
EDIT
If you wish to completely reinstall nodejs, check out the script located here:
https://gist.github.com/brock/5b1b70590e1171c4ab54
and check out this:
How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
It says Mac OSX, but it'll work perfectly fine in ubuntu, too.
depends on what version of latest nodejs you want to install
if LTS version or current latest version, then from PPA
latest LTS version
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
apt-get install nodejs
current latest version
apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt-get install nodejs
source: https://codesposts.com/ydOAwynW
Install the snap package
The easiest method to install Node.js on Ubuntu is to use the snap package. Just search for node on Ubuntu Software store and install the first one.
Or if you prefer command line:
sudo snap install node --classic
Alternate method: NVM
If you can't use snaps for some reason, like from a WSL environment, then Node Version Manager (NVM) is the way to go. It's safer than upgrading the node packages in Ubuntu to unsupported versions from PPAs or 3rd party repos, which may cause conflicts or breakages in apt package management system. Compared to NVM, manual installations from tarballs are harder to maintain and upgrade. Follow these steps to install the latest node using NVM:
Step 1: Install NVM
Run this command in Terminal:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Step 2: Install node
Once NVM installation is complete, close and reopen Terminal. Then run this command:
nvm install node
Step 3: Check node version
Run these commands:
node --version
npm --version
If everything went well, you'll see the latest node and npm versions as output. That's all, node is installed and ready to run! 😊
Note: This question is similar to the AskUbuntu question "How do I install the latest version of node.js?" and my answer equally applies. I'm reproducing my answer here to ensure a full complete answer exists rather than just a link.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y nano git curl vim htop gnupg2 && curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - && sudo apt-get install -y nodejs
Install NodeJS 14x and npm 7x in Ubuntu 2020 LTS
Install Nodesource: curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Install NodeJS: sudo apt-get install -y nodejs
Install latest npm: npm install -g npm#latest
For certain npm packages to run: sudo apt install build-essential
The easiest way is using a single line command is sudo snap install node --classic
It installs the latest stable node version from snap store.

Install latest nodejs version in ubuntu 14.04

This is the way I installed nodejs in ubuntu 14.04 LTS:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get install nodejs
When I checked the node version with this:
node -v
I get this
v0.10.37
But the latest version is 4.2.6 and 5.5.0. How can I get the latest or update version?
sudo apt-get install curl
For Node.js v4
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
For Node.js v5:
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
Node.js v6:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Node.js v7:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
Node.js 8:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
https://nodejs.org/en/download/package-manager/
On Ubuntu 14.04.5 LTSthe easier way is
1 Install npm:
sudo apt-get install npm
Install n
sudo npm install n -g
Get latest version of node
sudo n latest
If you prefer to install a specific version of `node you can
2.1 List available node versions
n ls
2.2 and the install a specific version
sudo n 4.5.0
There is an issue with node and npm update in Ubuntu14.04 LTS 64 bit OS. Since Google Chrome repository no longer provides 32-bit packages, 64-bit Ubuntu/Debian users will notice an error when updating the software sources, which looks as follows:
Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release
Unable to find expected entry 'main/binary-i386/Packages' in Release file (Wrong sources.list entry or malformed file)
Some index files failed to download. They have been ignored, or old ones used instead.
So to fix this issue, the repository must be specifically set for 64-bit only. This can be done by the command
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
i,e You should set it for 64 bit only before installing node.
So the exact procedure to install latest node and npm will be
sudo sed -i -e 's/deb http/deb [arch=amd64] http/' "/etc/apt/sources.list.d/google-chrome.list"
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
I had such an issue and got this solution from here. Hope this will help someone.
Here i am going to tell you how to install nodejs compile and install into your Linux Server.
Step 1-:
$ cd /opt/
$ wget https://nodejs.org/dist/v6.2.1/node-v6.2.1.tar.gz
Extract the tar.gz source code
$ tar -xvf node-*.tar.gz
Step 2-:
Compile and install the nodejs.
$ cd node-v6.2.1
$ ./configure
$ make
$ sudo make install
Note-:
If you found error “make command not found”
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential
$ gcc -v
$ make -v
Running Ubuntu Mate 14.04 LTS
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
nodejs -v
Checkout nvm. It manages node distributions for you, so you can have multiple projects running that use different nodejs versions.
nvm lets you choose exactly which version of node you need. With apt-get you will always only get the latest version that has been included into debian/ubuntu by those package maintainers, but those are usually very old. Especially in an area like nodejs, this is mostly not suitable.
This worked for me:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Hope it helps someone too :)
Assuming you already have npm package and want to upgrade nodejs version:
sudo npm install -g n
sudo n latest
In case you don't have installed npm package then itstall it using following command:
sudo apt-get install npm
On linux.
NVM (Node Version manager)
https://github.com/creationix/nvm
NVM installs both the latest stable node and npm for you
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca
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:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
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:
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
With this setup, you get for example:
which node
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
and:
which vaca
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
and if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
NodeJS require a global module/package
How do I import global modules in Node? I get "Error: Cannot find module <module>"?
so we see that everything is completely contained inside the specific node version.
Tested in Ubuntu 17.10.
Better way to do is,
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
based on version can change, setup_6.x into 7,8 etc
wget -qO- https://deb.nodesource.com/setup_X.x | sudo bash -
sudo apt-get install -y nodejs
You may also need to restart your terminal, on Ubuntu 17 installing latest version of NodeJS with sudo n 9.0.0
if you check the version with node -v it won't report correctly, close the terminal, open a new terminal and check again with node -v it will be reporting correctly
The easiest way for me:
Download the latest version of nodejs in https://nodejs.org/en/
Change directory to: cd /usr/local
Install the binaries, by using the following command:
sudo tar --strip-components 1 -xJf ~/Downloads/node-v14.16.0-linux-x64.tar.xz
node -v
npm -v
Ubuntu 14.04 contains a version of Node.js in its default repositories that can be used to easily provide a consistent experience across multiple servers. The version in the repositories is 0.10.25. This will not be the latest version, but it should be quite stable.
In order to get this version, we just have to use the apt package manager. We should refresh our local package index prior and then install from the repositories:
sudo apt-get update
sudo apt-get install nodejs
If the package in the repositories suits your needs, this is all that you need to do to get set up with Node.js. In most cases, you'll also want to also install npm, which is the Node.js package manager. You can do this by typing:
sudo apt-get install npm
This will allow you to easily install modules and packages to use with Node.js.
Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software.

Gulp global installation not possible [duplicate]

NodeJS interpreter name(node) on Ubuntu has been renamed to nodejs because of a name conflict with another package. Here's what the readme. Debian says:
The upstream name for the Node.js interpreter command is "node".
In Debian the interpreter command has been changed to "nodejs".
This was done to prevent a namespace collision: other commands use
the same name in their upstream, such as ax25-node from the "node"
package.
Scripts calling Node.js as a shell command must be changed to instead
use the "nodejs" command.
However, using nodejs mucks up installing packages using npm. Package installation fails with the following error:
sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read /usr/share/doc/nodejs/README.Debian
How do I make npm understand that nodejs is already installed on the system but the interpreter name is different?
TL;DR:
sudo apt-get install nodejs-legacy
First of all let me clarify the situation a bit. In summer 2012 Debian maintainers decided to rename Node.js executable to prevent some kind of namespace collision with another package. It was very hard decision for Debian Technical Committee, because it breaks backward compatibility.
The following is a quote from Committee resolution draft, published in Debian mailing list:
The nodejs package shall be changed to provide /usr/bin/nodejs, not /usr/bin/node. The package should declare a Breaks: relationship with
any packages in Debian that reference /usr/bin/node.
The nodejs source package shall also provide a nodejs-legacy binary package at Priority: extra that contains /usr/bin/node as a symlink to
/usr/bin/nodejs. No package in the archive may depend on or recommend
the nodejs-legacy package, which is provided solely for upstream
compatibility. This package declares shall also declare a Conflicts:
relationship with the node package.
<...>
Paragraph 2 is the actual solution for OP's issue. OP should try to install this package instead of doing symlink by hand. Here is a link to this package in Debian package index website.
It can be installed using sudo apt-get install nodejs-legacy.
I have not found any information about adopting the whole thing by NPM developers, but I think npm package will be fixed on some point and nodejs-legacy become really legacy.
Try linking node to nodejs. First find out where nodejs is
whereis nodejs
Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.
You can also install Nodejs using NVM or Nodejs Version Manager There are a lot of benefits to using a version manager. One of them being you don't have to worry about this issue.
Instructions:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
Once the prerequisite packages are installed, you can pull down the nvm installation script from the project's GitHub page. The version number may be different, but in general, you can download and install it with the following syntax:
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
This will download the script and run it. It will install the software into a subdirectory of your home directory at ~/.nvm. It will also add the necessary lines to your ~/.profile file to use the file.
To gain access to the nvm functionality, you'll need to log out and log back in again, or you can source the ~/.profile file so that your current session knows about the changes:
source ~/.profile
Now that you have nvm installed, you can install isolated Node.js versions.
To find out the versions of Node.js that are available for installation, you can type:
nvm ls-remote
. . .
v0.11.10
v0.11.11
v0.11.12
v0.11.13
v0.11.14
As you can see, the newest version at the time of this writing is v0.11.14. You can install that by typing:
nvm install 0.11.14
Usually, nvm will switch to use the most recently installed version. You can explicitly tell nvm to use the version we just downloaded by typing:
nvm use 0.11.14
When you install Node.js using nvm, the executable is called node. You can see the version currently being used by the shell by typing:
node -v
The comeplete tutorial can be found here
Install nvm first using:
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
Run command
source ~/.profile
Now run this and this will show will all installed or other versions of packages:
nvm ls-remote
Installed packages will be in green. Install whatever version you want:
nvm install 6.0.0
Check where is not installed:
which node
Check current version:
node -v
n=$(which node);
n=${n%/bin/node};
chmod -R 755 $n/bin/*;
sudo cp -r $n/{bin,lib,share} /usr/local
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs-legacy
source ~/.profile
Combined the accepted answer with source ~/.profile from the comment that has been folded and some clean up commands before. Most likely you will also need to sudo apt-get install npm after.
for me problem was solved by,
sudo apt-get remove node
sudo apt-get remove nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
alias node=nodejs
rm -r /usr/local/lib/python2.7/dist-packages/localstack/node_modules
npm install -g npm#latest || sudo npm install -g npm#latest
Here's another approach I use since I like n for easy switching between node versions.
On a new Ubuntu system, first install the 'system' node:
curl -sL https://deb.nodesource.com/setup | sudo bash -
Then install n module globally:
npm install -g n
Since the system node was installed first (above), the alternatives system can be used to cleanly point to the node provided by n. First make sure the alternatives system has nothing for node:
update-alternatives --remove-all node
Then add the node provided by n:
update-alternatives --install /usr/bin/node node /usr/local/bin/node 1
Next add node provided by the system (the one that was installed with curl):
update-alternatives --install /usr/bin/node node /usr/bin/nodejs 2
Now select the node provided by n using the interactive menu (select /usr/local/bin/node from the menu presented by the following command):
update-alternatives --config node
Finally, since /usr/local/bin usually has a higher precedence in PATH than /usr/bin, the following alias must be created (enter in your .bashrc or .zshrc) if the alternatives system node is to be effective; otherwise the node installed with n in /usr/local/bin takes always precedence:
alias node='/usr/bin/node'
Now you can easily switch between node versions with n <desired node version number>.
On Linux Mint 17, I tried both solutions (creating a symlink or using the nodejs-legacy package) without success.
The only thing that finally worked for me was using the ppa from Chris Lea:
sudo apt-get purge node-*
sudo apt-get autoremove
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
This installed node version 10.37 and npm 1.4.28. After that, I could install packages globally.
As other folks already mention, I will suggest not to use "sudo apt-get" to install node or any development library. You can download required version from https://nodejs.org/dist/v6.9.2/ and setup you own environment.
I will recommend tools like nvm and n, to manage you node version. It is very convenient to switch and work with these modules.
https://github.com/creationix/nvm
https://github.com/tj/n
Or write basic bash to download zip/tar, extract move folder and create a soft link. Whenever you need to update, just point the old soft link to new downloaded version.
Like I have created for my own, you can refer:
https://github.com/deepakshrma/NodeJs-4.0-Reference-Guide/blob/master/nodejs-installer.sh
#Go to home
cd ~
#run command
#New Script
wget https://raw.githubusercontent.com/deepakshrma/NodeJs-4.0-Reference-Guide/master/nodejs-installer.sh
bash nodejs-installer.sh -v lts
#here -v or --version can be sepecific to 0.10.37 or it could be latest/lts
#Examples
bash nodejs-installer.sh -v lts
bash nodejs-installer.sh -v latest
bash nodejs-installer.sh -v 4.4.2
Simple solution from here
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash --
sudo apt-get install nodejs
You can specify version by changing setup_x.x value, for example to setup_5.x
Your System is not able to detect the path node js binary.
1.which node
2.Then soft link node to nodejs
ln -s [the path of nodejs] /usr/bin/node
I am assuming /usr/bin is in your execution path. Then you can test by typing node or npm into your command line, and everything should work now.
Uninstall whatever node version you have
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs-legacy
sudo apt-get --purge remove nodejs
install nvm (Node Version Manager) https://github.com/creationix/nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Now you can install whatever version of node you want and switch between the versions.
I fixed it unlinking /usr/sbin/node (which is linked to ax25-node package), then I have create a link to nodejs using this on command line
sudo ln -s /usr/bin/nodejs /usr/bin/node
Because package such as karma doesn't work with nodejs name, however changing the first line of karma script from node to nodejs, but I prefer resolve this issue once and for all
For me the fix was removing the node* packages and also the npm packages.
Then a fresh install as:
sudo apt-get install autoclean
sudo apt-get install nodejs-legacy
npm install
Problem is not in installer
replace nodejs with node or change the path from /usr/bin/nodejs to /usr/bin/node
This is the your node is not properly install, first you need to uninstall the node then install again.
To install the node this may help you
http://array151.com/blog/nodejs-tutorial-and-set-up/
after that you can install the packages easily. To install the packages this may help you
http://array151.com/blog/npm-node-package-manager/
you can create a link ln -s nodejs node in /usr/bin
hope this solves your problem.
node -v // first check it's install or not
npm -v
sudo apt install npm
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
sudo apt-get install nodejs
then check
node -v or node –version
npm -v or npm –version
or you can remove package.lock json file / node_modules than run npm i
I hope it'll work fine
steps : https://www.geeksforgeeks.org/installation-of-node-js-on-linux/
Faced same issue, steps below worked for me.
Install curl on your system then run NVM installer script.
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Load the environment
source ~/.profile
Install the supported version of Node.js.
nvm install 16.15.1
Confirm the installation
node -v

How to install a specific version of Node on Ubuntu?

I would like to install NodeJS version 0.8.18 on Ubuntu 12.04. I tried to install the newest version and then reverting to 0.8.18 by using nvm, but when I run my code apparently there is some problem with the packages installed and the two versions (latest and 0.8.18). Since I don't know how to solve that problem, I cleaned the machine from the Node installation and thought about installing directly the version I'm interested in (v0.8.18).
The n module worked for me.
Run this code to clear npm’s cache, install n, and install the latest stable version of Node:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
See: http://www.hostingadvice.com/how-to/update-node-js-latest-version/
And: https://www.npmjs.com/package/n
To install a specific version of node:
sudo n 6.11.2
To check what version:
node -v
You might need to restart
Chris Lea has 0.8.23 in his ppa repo.
This package let you add a repository to apt-get: (You can also do this manually)
sudo apt-get install software-properties-common
Add Chris Lea's repository:
sudo apt-add-repository ppa:chris-lea/node.js-legacy
Update apt-get:
sudo apt-get update
Install Node.js:
sudo apt-get install nodejs=0.8.23-1chl1~precise1
I think (feel free to edit) the version number is optional if you only add node.js-legacy. If you add both legacy and ppa/chris-lea/node.js you most likely need to add the version.
NVM (Node Version manager)
https://github.com/nvm-sh/nvm
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
Tested in Ubuntu 17.10:
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | sh
source ~/.nvm/nvm.sh
nvm install 0.9.0
nvm install 0.9.9
nvm use 0.9.0
node --version
#v0.9.0
nvm use 0.9.9
node --version
#v0.9.9
For the particular case of the most recent long term support version (recommended if you can choose):
nvm install --lts
nvm use --lts
npm --version
npm install --global vaca
vaca
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:
f="$HOME/.nvm/nvm.sh"
if [ -r "$f" ]; then
. "$f" &>'/dev/null'
nvm use --lts &>'/dev/null'
fi
With this setup, you get for example:
which node
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/node
and:
which vaca
gives:
/home/ciro/.nvm/versions/node/v0.9.0/bin/vaca
and if we want to use the globally installed module:
npm link vaca
node -e 'console.log(require.resolve("vaca"))'
gives:
/home/ciro/.nvm/versions/node/v0.9.0/lib/node_modules/vaca/index.js
as mentioned at:
NodeJS require a global module/package
How do I import global modules in Node? I get "Error: Cannot find module <module>"?
so we see that everything is completely contained inside the specific node version.
For projects however, you are better off just using packages installed locally under node_modules and npx for executable to be able to have independent versions across projects, global usage is mostly for the Node executable itself and global CLI utilities not specific to any project.
Setting the NPM version
Simply:
npm install npm#6.14.13 -g
The executable is placed inside the current NVM version, so everything remains nice and isolated, e.g.:
which npm
gives something like:
/home/ciro/.nvm/versions/node/v14.17.0/bin/npm
How can I change the version of npm using nvm?
It is possible to install specific version of nodejs from nodejs official distribution with using dpkg.
Check the version of you ubuntu distribution, cat /etc/lsb-release.
Check architecture of your os, uname -m.
Download preferred version of debian package from nodejs official site.
For 4.x, https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/
For 5.x, https://deb.nodesource.com/node_5.x/pool/main/n/nodejs/
For 0.12.x, https://deb.nodesource.com/node_0.12/pool/main/n/nodejs/
Be careful to check nodejs-dbg or nodejs in filename.
For example, currently recent 4.x version is 4.2.4, but you can install previous 4.2.3 version.
curl -s -O https://deb.nodesource.com/node_4.x/pool/main/n/nodejs/nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
sudo apt-get install rlwrap
sudo dpkg -i nodejs_4.2.3-1nodesource1~trusty1_amd64.deb
Try this way. This worked me.
wget nodejs.org/dist/v0.10.36/node-v0.10.36-linux-x64.tar.gz(download file)
Go to the directory where the Node.js binary was downloaded to, and then run command i.e, sudo tar -C /usr/local --strip-components 1 -xzf node-v0.10.36-linux-x64.tar.gz to install the Node.js binary package in “/usr/local/”.
You can check:-
$ node -v
v0.10.36
$ npm -v
1.4.28
In ubuntu specific version of node can be installed with help of nvm
install nvm
sudo apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
To install a particular version of node, use the command nvm install and add the number of the version.
nvm install 10.15.2
node -v
Say you want to install Node 10,
Firstly, download and execute the Node.js 10.x installer:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
This will add a source file for the official Node.js 10.x repo, grabs the signing key
Once the installer is done doing it’s thing, you will need to install (or upgrade) Node.js:
sudo apt install nodejs
version 0.10 is also avaible with this ppa
apt-add-repository ppa:chris-lea/node.js
install nodejs with:
apt-get install nodejs=0.10.25-1chl1~precise1
Thanks to my friend Julian Xhokaxhiu
I imagine many directed here are looking for this to add to a Dockerfile
RUN set -x \
&& curl -sL 'https://deb.nodesource.com/setup_16.x' | bash - \
&& apt-get -y install nodejs \
&& ln -s /usr/bin/nodejs /usr/local/bin/node
FYI, according to this page in the wiki of the nodejs github repo, Chris Lea's PPA (mentioned in several other answers) has been superseded by the NodeSource distributions as the main way of installing nodejs from source in Ubuntu:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
This is supported for the three latest (at the time of writing this) LTS versions of Ubuntu: 10.04 (lucid), 12.04 LTS (precise) and 14.04 (trusty).
I'm not sure this will help in installing an old version of nodejs, but I'm putting this here in case it helps others who needed to install a specific (newer) version of nodejs that isn't included in their distro's repositories.
yes, its a duplicate answer but I insist using n module to install a specific version(following commands installs node version 6.9.5).
npm install -g n
n 6.9.5
NOTE: you can use NVM software to do this in a more nodejs fashionway.
However i got issues in one machine that didn't let me use NVM. So i
have to look for an alternative ;-)
You can manually download and install.
go to nodejs > download > other releases
http://nodejs.org/dist/
choose the version you are looking for
http://nodejs.org/dist/v0.8.18/
choose distro files corresponding your environmment and download (take care of 32bits/64bits version).
Example: http://nodejs.org/dist/v0.8.18/node-v0.8.18-linux-x64.tar.gz
Extract files and follow instructions on README.md :
To build:
Prerequisites (Unix only):
* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* libexecinfo (FreeBSD and OpenBSD only)
Unix/Macintosh:
./configure
make
make install
If your python binary is in a non-standard location or has a
non-standard name, run the following instead:
export PYTHON=/path/to/python
$PYTHON ./configure
make
make install
Windows:
vcbuild.bat
To run the tests:
Unix/Macintosh:
make test
Windows:
vcbuild.bat test
To build the documentation:
make doc
To read the documentation:
man doc/node.1
Maybe you want to (must to) move the folder to a more apropiate place like /usr/lib/nodejs/node-v0.8.18/ then create a Symbolic Lynk on /usr/bin to get acces to your install from anywhere.
sudo mv /extracted/folder/node-v0.8.18 /usr/lib/nodejs/node-v0.8.18
sudo ln -s /usr/lib/nodejs/node-v0.8.18/bin/node /usr/bin/node
And if you want different release in the same machine you can use debian alternatives. Proceed in the same way posted before to download a second release. For example the latest release.
http://nodejs.org/dist/latest/ -> http://nodejs.org/dist/latest/node-v0.10.28-linux-x64.tar.gz
Move to your favorite destination, the same of the rest of release you want to install.
sudo mv /extracted/folder/node-v0.10.28 /usr/lib/nodejs/node-v0.10.28
Follow instructions of the README.md file. Then update the alternatives, for each release you have dowload install the alternative with.
sudo update-alternatives --install genname symlink altern priority [--slave genname symlink altern]
Add a group of alternatives to the system. genname is the
generic name for the master link, symlink is the name of its
symlink in the alternatives directory, and altern is the
alternative being introduced for the master link. The arguments
after --slave are the generic name, symlink name in the
alternatives directory and alternative for a slave link. Zero
or more --slave options, each followed by three arguments, may
be specified.
If the master symlink specified exists already in the
alternatives system’s records, the information supplied will be
added as a new set of alternatives for the group. Otherwise, a
new group, set to automatic mode, will be added with this
information. If the group is in automatic mode, and the newly
added alternatives’ priority is higher than any other installed
alternatives for this group, the symlinks will be updated to
point to the newly added alternatives.
for example:
sudo update-alternatives --install /usr/bin/node node /usr/lib/nodejs/node-v0.10.28 0 --slave /usr/share/man/man1/node.1.gz node.1.gz /usr/lib/nodejs/node-v0.10.28/share/man/man1/node.1
Then you can use update-alternatives --config node to choose between any number of releases instaled in your machine.
To install a specific version of nodejs in Ubuntu you can use below commands, just specify and replace the version number, for example, node_12.x will fetch the latest of 12.
curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs
FYI the available version for raring in Chris Lea's repo is currently 0.8.25
sudo apt-get install nodejs=0.8.25-2chl1~raring1
The Node.js project recently pushed out a new stable version with the 0.10.0 release
Use the following command on Ubuntu 13x
sudo apt-get install nodejs=0.10.18-1chl1~raring1
Install nvm using the following commands in the same order.nvm stands for node version manager.
sudo apt-get update
sudo apt-get install build-essential checkinstall libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
In case the above command does not work add -k after -o- .It should be as below:
curl -o- -k https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
Then nvm ls-remote to see the available versions.
In case you get N/A in return,run the following.
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
alternatively you can run the following commands too
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Then nvm install #.#.# replacing # by version(say nvm 8.9.4)
finally nvm use #.#.#
Here is a list of available builds for debian: https://github.com/nodesource/distributions/tree/master/deb
For this example, lets assume you want version 14 (LTS at the time of writing)
We can download this script from github, execute it and install the version of node we want. For security reasons it's a good idea to read the script prior to executing it.
curl -sL https://raw.githubusercontent.com/nodesource/distributions/master/deb/setup_14.x | bash
apt-get install -y nodejs # may or may not require sudo based on your setup
I like this approach because it doesn't require extraneous dependencies like nvm to target specific versions
If you are building for a different distro or architecture you can find more builds here https://nodejs.org/dist/

Resources