How to bring `npm` back? - node.js

I installed nodejs via nvm on Ubuntu server, and found issues with jenkins tasks. So I uninstalled nvm, and reinstalled nodejs by
sudo apt-get install curl
curl --silent --location https://deb.nodesource.com/setup_5.x | sudo bash -
sudo apt-get install nodejs
And now on my Ubuntu server, the node is back but npm wasn't, how to reinstall npm?
This is my command echo back:
$ node -v
5.8.0
$ npm -v
-bash: /home/ubuntu/.nvm/versions/node/v5.8.0/bin/npm: No such file or directory

I think this will help you:
sudo apt-get install --reinstall npm

Finally I found the solution:
curl http://npmjs.org/install.sh | sudo sh

Related

Nodejs and npm installation on Ubuntu

I am pursuing a course which asked me to install Nodejs and npm using below commands. But I am not able to understand the very first command, what exactly it is doing and how to write it on the terminal.
$ sudo bash -c "cat >/etc/apt/sources.list.d/nodesource.list" <
deb https://deb.nodesource.com/node_6.x xenial main
deb-src https://deb.nodesource.com/node_6.x xenial main
EOL
$ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
$ sudo apt update
$ sudo apt install nodejs
I checked the Nodejs site and they are just recommending below command to install Nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Please guide me what should I do, I have to install Nodejs v6.9 and npm version 3.x
I would recommend to you to install required Node version via NVM. NVM is tool that helps you to change Node version on your machine. So you can use any Node version you want, even 6.9.
In order to install NVM you have to run this command:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
You can verify NVM installation with this command:
command -v nvm
After that you can install required version of Node:
nvm install v6.9
If you install multiple version of Node, you can switch from one version to another:
nvm use v6.9
You can install a specific version of NodeJS using NVM:
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.9/install.sh | bash
Now close the terminal and open it again and type:
command -v nvm
If the terminal outputs nvm you're good to go.
Next you can install the version you want:
nvm install 6.9.0
nvm use 6.9.0
And if everything is ok, it should output you this:
Now using node v6.9.0 (npm v3.10.8)

Package 'npm' has no installation candidate

I want to install npm in Debian 9.
I've tried:
apt-get install nodejs
completely installed and nodejs -v results: v4.8.2.
but when try to run npm an error says:
bash: npm: command not found
Base on my searches I've tried other ways:
based on this guide: https://www.godaddy.com/help/install-nodejs-ubuntu-17395 I've tried:
sudo apt-get install npm
results:
E: Package 'npm' has no installation candidate
Based on another guide I've tried:
wget https://npmjs.org/install.sh
sudo chmod +x install.sh
sudo ./install.sh
results:
npm cannot be installed without node.js.
of course I've installed nodejs. I also tried this way:
curl --silent --location https://deb.nodesource.com/setup_0.12 | sudo bash -
sudo apt-get update
sudo apt-get install --yes nodejs
It says:
nodejs is already the newest version (4.8.2~dfsg-1).
What should I do?
Remove the old version
sudo apt-get purge nodejs
Install the new version:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Alternatively, for Node.js 9:
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
Source
It might tell you that you are missing package gnupg2, just install it.

How to Install node8 and latest npm in ubuntu

Hi i have installed node v4.2.6 and npm 3.5.2 in my ubuntu but now when i try to install latest version or node6.x then i am getting some errors in my terminal of Packages 404 Not Found. i have also attached the screenshot. please let me know how can i fix it?
i also have tried :-
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
# Then install with:
sudo apt-get install -y nodejs
still got the same output and i guess i made one mistake by running a command :-
sudo sed -i -e 's/:\/\/(archive.ubuntu.com\|security.ubuntu.com)/old-releases.ubuntu.com/g' /etc/apt/sources.list
as mentioned in https://smyl.es/how-to-fix-ubuntudebian-apt-get-404-not-found-package-repository-errors-saucy-raring-quantal-oneiric-natty/
Here is the output of sudo apt-get update
i dont know what is your ubuntu version but if it's on 16.4 you can do this commands :
$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev
after that :
$ curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
and after do this commands :
$ nano install_nvm.sh
and after that close the nano and do this command :
$ bash install_nvm.sh
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
and the out put looks like this :
....
v5.8.0
v5.9.0
v5.9.1
v5.10.0
v5.10.1
v5.11.0
v6.0.0
...
v8.4.0
now you can simply type this command to install the v8.4.0 of nodejs :
$ nvm install 8.4.0
and at the last step you can type this command to use the last version :
$ nvm use 8.4.0
and it's done!
You are using wrong package url, you must use
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Reference: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
I would suggest to use nvm as a nodejs and npm manager.
Then you can easily install required version of node with nvm install node x.x
command

updating nodejs on ubuntu 16.04

I was recently going through the version of node in my ubuntu 16.04 when node -v command was used it shows me version 6.9.1 but when nodejs -v it shows 6.9.2 previously before using this commands npm update command was used.
Now what's these difference in node -v and nodejs -v? and how to update to the latest LTS version of node/nodejs?
To update, you can install n
sudo npm install -g n
Then just :
sudo n latest
or a specific version
sudo n 8.9.0
According to official docs to install node on Debian and Ubuntu based distributions:
node v12 (Old)
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
node v14 (For new users: install this one):
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
node v15 (Current version):
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -
sudo apt-get install -y nodejs
Other older versions:
Just replace the desired version number in the link above.
Optional: install build tools
To compile and install native packages
sudo apt-get install -y build-essential
To update node to the latest version just:
sudo apt update
sudo apt upgrade
To keep npm updated
sudo npm i -g npm
To find out other versions try npm info npm and in versions find your desired version and replace [version-tag] with that version tag in npm i -g npm#[version-tag]
And I also recommend trying yarn instead of npm
Using Node Version Manager (NVM):
Install it:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Test your installation:
close your current terminal, open a new terminal, and run:
command -v nvm
Use it to install as many versions as u like:
nvm install 8 # Install nodejs 8
nvm install --lts # Install latest LTS (Long Term Support) version
List installed versions:
nvm ls
Use a specific version:
nvm use 8 # Use this version on this shell
Set defaults:
nvm alias default 8 # Default to nodejs 8 on this shell
nvm alias default node # always use latest available as default nodejs for all shells
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
Undo :
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n
Use sudo apt-get install --only-upgrade nodejs to upgrade node (and only upgrade node) using the package manager.
The package name is nodejs, see https://stackoverflow.com/a/18130296/4578017 for details.
You can also use nvm to install and update node.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
Then restart the terminal, use nvm ls-remote to get latest version list of node, and use nvm install lts/* to install latest LTS version.
nvm is more recommended way to install or update node, even if you are not going to switch versions.
Difference: When I first installed node, it installed as 'nodejs'. When I upgraded it, it created 'node'. By executing node, we are actually executing nodejs. Node is just a reference to nodejs.
From my experience, when I upgraded, it affected both the versions (as it is supposed to). When I do nodejs -v or node -v, I get the new version.
Upgrading: npm update is used to update the packages in the current directory. Check https://docs.npmjs.com/cli/update
To upgrade node version, based on the OS you are using, follow the commands here https://nodejs.org/en/download/package-manager/
Please refer nodejs official site for installation instructions at the following link
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
Anyway, please find the commands to install nodejs version 10 in ubuntu below.
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install npm#latest -g
Try this:
Edit or create the file :nodesource.list
sudo gedit /etc/apt/sources.list.d/nodesource.list
Insert this text:
deb https://deb.nodesource.com/node_10.x bionic main
deb-src https://deb.nodesource.com/node_10.x bionic main
Run these commands:
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
sudo sh -c "echo deb https://deb.nodesource.com/node_10.x cosmic main /etc/apt/sources.list.d/nodesource.list"
sudo apt-get update
sudo apt-get install nodejs
node and nodejs are two different packages in Ubuntu software, node is an up-to-date snap package, whereas nodejs is an older version of apt package
to update to the latest LTS version of node:
Install NVM on Ubuntu 22.04|20.04|18.04 with the command:
wget https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh
bash install.sh
After the installation, source the profile:
source ~/.bashrc
Verify the NVM installation:
nvm -v
Install Node.js 18 LTS on Ubuntu 22.04|20.04|18.04 as shown:
nvm install v18
Install the latest version using the command:
nvm install node
Once complete, verify the installation:
node -v
Run these commands:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.profile
nvm ls-remote
nvm install v9.10.1
nvm use v9.10.1
node -v
Update latest version Nodejs :
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
I am using Ubuntu 20.04.4 LTS and got the issue during upgrade node js. The current LTS version is 16.14.2 According to the NodeSource Node.js Binary Distributions document
Node.js v16.x:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs
if you still get the issue you can also try the following:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
apt-get update
sudo npm cache clean -f
sudo apt-get install -y nodejs
Node.js Current:
It's work for me..
Using Ubuntu
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
Using Debian, as root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
I am also facing problem while going to install react app, so i found the solution,
npx create-react-app shodkk
First install the npm latest version using
sudo npm install -g npm#8.4.1
So to install the node 16.x you need to go terminal and type
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
Doing this you install the node LTS that is 16.14.o at the time of writing this post.
Try this 2-3 times, also do the
sudo apt-get update
Then Now install the package using
sudo apt-get install -y nodejs
At last this helps you remove any unwanted package, that remains after updating that is depreciated and need not be there, So use autoremove command.
sudo apt autoremove
So if like the post, Upvote and motivate me to write more, thanks, givingBack to the Community.
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
To undo:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g n

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.

Resources