我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。
如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?
我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。
如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?
当前回答
对于v4 LTS版本使用:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs
对于Node.js v6的使用:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
在尝试在Amazon Linux上安装本机插件时,我也遇到了一些问题。如果你想这样做,你也应该安装构建工具:
yum install gcc-c++ make
其他回答
对于v4 LTS版本使用:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs
对于Node.js v6的使用:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
在尝试在Amazon Linux上安装本机插件时,我也遇到了一些问题。如果你想这样做,你也应该安装构建工具:
yum install gcc-c++ make
sudo yum install nodejs npm——enablerepo=epel适用于Amazon Linux AMI。 Curl—silent—location https://rpm.nodesource.com/setup_6.x | bash - Yum -y安装nodejs 在红帽公司工作。
对我有用的程序(遵循这些相当旧的说明,并进行了一些更新):
check git is installed git --version or install it via: sudo yum install git install gcc and openssl: sudo yum install gcc-c++ make sudo yum install openssl-devel clone the git repo into a directory called node (which you can remove later): git clone https://github.com/nodejs/node.git decide which version of node you want at https://github.com/nodejs/node/releases go to the node directory just created and install node cd node git checkout v6.1.0 - put your desired version after the v ./configure make sudo make install test that node is installed / working with either node --version or simply node (exit node via process.exit() or ^C x 2 or ^C + exit) check the npm version: npm --version and update if necessary via sudo npm install -g npm Optional: remove the node directory with rm -r node
注:
The accepted answer didn't work since sudo yum install nodejs --enablerepo=epel-testing returns the error: No package nodejs available. ...and sudo yum install nodejs --enablerepo=epel (ie without -testing) only gave very old versions. If you already have an old version of node installed you can remove it with: sudo npm uninstall npm -g ...since npm can uninstall itself sudo yum erase nodejs sudo rm -f /usr/local/bin/node (sudo yum rm nodejs in the accepted answer won't work as rm is not a valid yum command see yum --help) It's possible to clone the node repo via git clone git://github.com/nodejs/node.git rather than git clone https://github.com/nodejs/node.gitbut you may get a various errors (see here). If you already have a /node dir from a previous install, remove it before using the git clone command (or there'll be a conflict): rm -r node If you have trouble with any sudo npm... command - like sudo: npm: command not found and/or have permissions issues installing node packages without sudo, edit sudo nano /etc/sudoers and add :/usr/local/bin to the end of the line Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin so that it reads Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
似乎没有人提到这一点。在Amazon Linux 2上,加载EPEL的官方方式是:
Sudo amazon-linux-extras安装epel
...那么你可以:
Sudo yum安装nodejs
参见Extras Library (Amazon Linux 2)
偶然发现了这个,奇怪的是后来很难再找到了。为子孙后代写在这里:
sudo yum install nodejs npm --enablerepo=epel
EDIT 3:截至2016年7月,EDIT 1不再适用于nodejs 4 (EDIT 2也一样)。这个答案(https://stackoverflow.com/a/35165401/78935)给出了一个真正的单行程序。
编辑1:如果你正在寻找nodejs 4,请尝试EPEL测试repo:
sudo yum install nodejs --enablerepo=epel-testing
编辑2:使用上面的命令从EPEL repo安装的nodejs 0.12升级到EPEL测试repo的nodejs 4,请遵循以下步骤:
sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing
较新的包将节点二进制文件放在/usr/bin中,而不是/usr/local/bin。
一些背景知识:
选项——enablerepo=epel会导致yum在epel存储库中搜索包。
EPEL (Extra Packages for Enterprise Linux) is open source and free community based repository project from Fedora team which provides 100% high quality add-on software packages for Linux distribution including RHEL (Red Hat Enterprise Linux), CentOS, and Scientific Linux. Epel project is not a part of RHEL/Cent OS but it is designed for major Linux distributions by providing lots of open source packages like networking, sys admin, programming, monitoring and so on. Most of the epel packages are maintained by Fedora repo. Via http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/