centOS can't install nodejs via yum - node.js

I was using node v0.10.x on my centOS server and I want to update node.js, so followed some articles. First removing currently installed:
# which node
# cd /usr
# rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
and then check node -v is not working, good. But using yum doesn't install latest Node.js, so I searched some post and found this:
https://www.metachris.com/2015/10/how-to-install-nodejs-5-on-centos-and-ubuntu/
so I followed commands:
# rpm -Uvh https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm
# yum install nodejs -y
and this is the problem. it prints numerous errors and keeps failing.
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-4.el6 will be updated
--> Processing Dependency: nodejs(x86-64) = 0.10.42-4.el6 for package: nodejs-devel-0.10.42-4.el6.x86_64
---> Package nodejs.x86_64 0:5.11.1-1nodesource.el7.centos will be an update
--> Running transaction check
---> Package nodejs-devel.x86_64 0:0.10.42-4.el6 will be updated
---> Package nodejs-devel.x86_64 0:5.11.1-1nodesource.el7.centos will be an update
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
nodejs x86_64 5.11.1-1nodesource.el7.centos nodesource 8.7 M
Updating for dependencies:
nodejs-devel x86_64 5.11.1-1nodesource.el7.centos nodesource 7.6 M
Transaction Summary
================================================================================
Upgrade 1 Package (+1 Dependent package)
Total size: 16 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction check error:
file /usr/lib/node_modules/npm/node_modules/semver/package.json from install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
file /usr/lib/node_modules/npm/node_modules/semver/bin/semver from install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
file /usr/lib/node_modules/npm/node_modules/semver/semver.js from install of nodejs-5.11.1-1nodesource.el7.centos.x86_64 conflicts with file from package nodejs-semver-2.1.0-1.el6.noarch
... and keeps going on ...
Also before remove node, I also did this:
# npm cache clean -f
# npm install -g n
# n stable
but this isn't working at all, because always saying version 0.10.x, even downloaded latest one! ( I sawed 6.2.2 or something )
I think something messed up on my server and I don't know how to fix this. Can anyone gimme some advice? Also If can, I want to install latest Node.js.

Install Node from the EPEL Repository
yum update
yum install epel-release
yum install nodejs
node --version
To access npm to manage their Node packages.
yum install npm

The easiest way is to use nvm, the "Node Version Manager".
In a shell, do:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Note: If you want to understand the script before running it, read the docs on nvm github page and/or remove | bash from the curl command to read without running the .sh file
Close and re-open shell to use updated profile. Then:
//prints "nvm" if correctly installed
$ command -v nvm
// install latest version of node
$ nvm install node
//check it's installed correctly
$ node -v
v12.6.0
After failing with other methods, this one had no issues.

First, you must install epe-release
sudo yum install epel-release
After, you can install node.js and npm
sudo yum -y install nodejs npm
Its worked for me.

I spent a while on this on a Fedora 35 workstation (upgraded from Fedora 34),
$ yum repolist
nodesource Node.js Packages for Fedora Linux 34 - x86_64
it gave me
$ node --version v12.22.1
None up the installers made a difference until I found this explanation:
How To Install Node.js on Fedora 36/35/34
The tutorial includes 3 methods. It's the third one that worked for me.
Install Node.js on Fedora via NVM
First, install the NVM tool on your system by running the following command:
$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Then, reload the system environment using this command. It will set the required environment variables to use nvm on the system.
$ source ~/.bashrc
$ nvm install v16.14
Downloading and installing node v16.14.2...
$ node --version
v16.14.2

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.

I have try to install node js 4.3.2 version but it give error

sudo apt-get install nodejs=4.3.2
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '4.3.2' for 'nodejs' was not found
Do you specifically want to install version 4.? The newest available is 12..
For installation of a specific version use apt-get install package=version -V. If this does not work for you please provide more info about your linux distro & version. You can always download the right Version of node manually on nodejs.org. You could also build it yourself.
Also check version availability for your system with sudo apt policy nodejs
Either way, first remove the previous installation completele, using
sudo apt-get purge package_name
then try installing the current version with PPA, by first running
sudo apt-get update
sudo apt-get install nodejs
after that you can check the version with node -v and for npm with npm -v
Try installing NodeJS using NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
check NVM is installed properly
nvm --version
To install the latest stable version
nvm install stable
Or a specific version
nvm install 12.4.0
nvm install 4
To list locally available Node JS versions
nvm list
Switch NodeJS version
nvm use version
Eg : nvm use 4
To make nodejs available for all users
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Or Install it manually by downloading
https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-x64.tar.xz

sudo npm i npm or sudo npm install npm#latest -g throws an error of EACCES:permission denied

I have npm v 5.6 and I installed node version 10.1 so the current npm doesn't support node version while updating npm I am getting EACCES permission denied error. I tried removing npm directory and updating via several command the npm version is stuck at 5.6. Help!!
Using Ubuntu v16.04 LTS.
I tried installing different nodejs version too but it also doesnt change npm version(npm v5.6).
visit here for the screenshot
I'd recommend using a version manager (such as nvm) to install multiple versions of Node.js and switch between them at will.
First off, make sure you have git and the build-essential package installed:
sudo apt-get update
sudo apt-get install build-essential git
Then install nvm with cURL (run this command in your terminal):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
This will clone the nvm repository to ~/.nvm and will make the required changes to your bash profile, so that nvm is available from anywhere in your terminal.
Reload your bash profile:
source ~/.bashrc
and verify the install by typing:
command -v nvm
which should output 'nvm' if the installation was successful.
(if this doesn't work, just close, then reopen your terminal)
And that’s it, nvm is installed and ready to be used.
Now, to download, compile, and install the latest release of Node, run the following from your terminal:
nvm install node
And then in any new shell just use the installed version:
nvm use node
Finally, verify the correct version is being used:
node -v
=> 10.5.0
There's a lot more to using nvm, such as installing multiple Node versions.
You can read more about that here: https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/
HTH

How do I find the old version of node js?

I'm trying to install "n", the nom helper on Amazon Linux. I'm having difficulty. It seems I have an old version of the node somewhere but I can't figure out where. When I run
npm install -g n
I get the below error ...
[myuser#mymachine ~]$ sudo /usr/local/bin/npm install -g n
ERROR: npm is known not to run on Node.js v0.10.48
You'll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8. You can find the
latest version at https://nodejs.org/
[myuser#mymachine ~]$ npm -v
5.4.2
╭─────────────────────────────────────╮
│ │
│ Update available 5.4.2 → 5.5.1 │
│ Run npm i -g npm to update │
│ │
╰─────────────────────────────────────╯
But notice that when I run
[myuser#mymachine ~]$ node -v
v8.8.1
it tells me I have v8.8.1 installed, which is what I intended. How do I purge the old, unwanted version of the node so I can install my helper?
Easiest solution would be to try the following to cleanup your node issues and reinstall a clean version.
First remove everything related to node
sudo apt-get purge --auto-remove nodejs npm
UPDATE For yum:
yum clean all
yum -y remove nodejs
Remove these leftover files and folders as well
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node opt/local/include/node /opt/local/lib/node_modules
Then install node back with nvm,
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
//To uninstall a node version
//nvm uninstall <current version>
nvm install 8.8.1
nvm use 8.8.1
//check with
node -v
npm -v
//**UPDATE**: Install your package
npm install -g n
And all should work.
UPDATE : Install Without NVM
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash -
yum install nodejs
node -v
//Install your package
npm install -g n
check the releases notes of node https://nodejs.org/en/download/releases/ you can download older version from this site
An alternative to installing Node.js through apt is to use a specially designed tool called nvm, which stands for "Node.js version manager".
Using nvm, you can install multiple, self-contained versions of Node.js which will allow you to control your environment easier. It will give you on-demand access to the newest versions of Node.js, but will also allow you to target previous releases that your app may depend on.
To start off, we'll need to get the software packages from our Ubuntu repositories that will allow us to build source packages. The nvm script will leverage these tools to build the necessary components:
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 it with curl:
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
And inspect the installation script with nano:
nano install_nvm.sh
Run the script with bash:
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
Output
...
v5.8.0
v5.9.0
v5.9.1
v5.10.0
v5.10.1
v5.11.0
v6.0.0
As you can see, the newest version at the time of this writing is v6.0.0. You can install that by typing:
nvm install 6.0.0
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 6.0.0
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
Output
v6.0.0
If you have multiple Node.js versions, you can see what is installed by typing:
nvm ls
If you wish to default one of the versions, you can type:
nvm alias default 6.0.0
This version will be automatically selected when a new session spawns. You can also reference it by the alias like this:
nvm use default
Each version of Node.js will keep track of its own packages and has npm available to manage these.

How to upgrade Node js version to 0.12.4 on Ubuntu

I want to upgrade Node JS version on Ubuntu.
I tried many commands but its version is still the older i.e v0.10.37.
I tried:
sudo npm install -g n
sudo n install 0.12.4
sudo n use 0.12.4
Also tried with nvm but non of them works for me. How can I upgrade Node Js version to 0.12.4?
Use npm in order to upgrade node
First Clean the cache and try
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.12.4
Then create a symbolic link(It is needed only sometimes, first try with these three commands. If it doesnot work add this.)
It will be updated to 0.12.4 Version.
It could be enough just to install n module:
sudo npm install -g n
and then simply run:
sudo n 0.12.4
The trick is that it may not be updated in your current terminal session. So you can simply open one more tab in your terminal or just another terminal and check your nodejs version by:
node --version
That's it, output will be v0.12.4
The official doc from nodejs repository points to this : https://nodesource.com/blog/nodejs-v012-iojs-and-the-nodesource-linux-repositories#installing-node-js-v0-12
Just follow it and you'll have the 0.12.4.
Try running this in terminal:
nvm install 5.10.1
nvm use 5.10.1
The version may be change.
Cheers!
Execute following comand to upgrade nodejs to 0.12.x
Note the new setup script name for Node.js v0.12
curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -
Then install with:
sudo apt-get install -y nodejs
Just ignore warning. By executing both commands it worked for me on Ubuntu 14.04
On Ubuntu 16.04
There is no special or dedicated comand to upgrade node version. The correct way to install or upgrade node on ubuntu is:
1) download the distribution you wish from nodejs official site, move the file into a known path
2) open a terminal and run: >sudo tar -C /usr/local --strip-components 1 -xzf "known path/name_of_the_distribution_file...gz
3) test if everything is ok: open a new terminal and run node --version. It should echo the version you downloaded and installed/upgraded.

Resources