centOS can't install nodejs via yum
Solution 1
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
Solution 2
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.
modernator
Hello, I'm .modernator. My hobby is studying computer science, theorem and programming. I'm fullstack developer who lived in South Korea, Busan City. You can visit my personal blog: http://modernator.me or my personal company web site http://team.modernator.me . Any questions or contacts are welcome. Please don't hesitate me text: [email protected]
Updated on June 27, 2022Comments
-
modernator almost 2 years
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.