如何在 Amazon Linux 上 yum 安装 Node.JS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27350634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to yum install Node.JS on Amazon Linux
提问by Tim Fulmer
I've seen the writeup on using yum to install the dependencies, and then installing Node.JS & NPM from source. While this does work, I feel like Node.JS and NPM should both be in a public repo somewhere.
我看过有关使用 yum 安装依赖项,然后从源代码安装 Node.JS 和 NPM 的文章。虽然这确实有效,但我觉得 Node.JS 和 NPM 都应该在某个地方的公共仓库中。
How can I install Node.JS and NPM in one command on AWS Amazon Linux?
如何在 AWS Amazon Linux 上通过一个命令安装 Node.JS 和 NPM?
回答by Tim Fulmer
Stumbled onto this, was strangely hard to find again later. Putting here for posterity:
偶然发现了这个,奇怪的是后来很难再找到。放在这里供后人使用:
sudo yum install nodejs npm --enablerepo=epel
EDIT 3:As of July 2016, EDIT 1no longer works for nodejs 4 (and EDIT 2neither). This answer (https://stackoverflow.com/a/35165401/78935) gives a true one-liner.
编辑 3:截至 2016 年 7 月,编辑 1不再适用于 nodejs 4(和EDIT 2都不适用)。这个答案(https://stackoverflow.com/a/35165401/78935)给出了一个真正的单线。
EDIT 1:If you're looking for nodejs 4, please try the EPEL testing repo:
编辑 1:如果您正在寻找 nodejs 4,请尝试 EPEL 测试存储库:
sudo yum install nodejs --enablerepo=epel-testing
EDIT 2:To upgrade from nodejs 0.12 installed through the EPEL repo using the command above, to nodejs 4 from the EPEL testing repo, please follow these steps:
编辑 2:要使用上面的命令从通过 EPEL 存储库安装的 nodejs 0.12 升级到 EPEL 测试存储库中的 nodejs 4,请按照下列步骤操作:
sudo yum rm nodejs
sudo rm -f /usr/local/bin/node
sudo yum install nodejs --enablerepo=epel-testing
The newer packages put the node binaries in /usr/bin, instead of /usr/local/bin.
较新的包放在节点的二进制文件/usr/bin,而不是/usr/local/bin。
And some background:
还有一些背景:
The option --enablerepo=epelcauses yumto search for the packages in the EPEL repository.
该选项--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/
EPEL (Extra Packages for Enterprise Linux) 是 Fedora 团队基于开源和免费社区的存储库项目,它为 Linux 发行版提供 100% 高质量的附加软件包,包括 RHEL(Red Hat Enterprise Linux)、CentOS 和 Scientific Linux。Epel 项目不是 RHEL/Cent OS 的一部分,但它是为主要的 Linux 发行版设计的,它提供了许多开源包,如网络、系统管理、编程、监控等。大多数 epel 包由 Fedora 仓库维护。
通过http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/
回答by Matthew Herbst
Like others, the accepted answer also gave me an outdated version.
像其他人一样,接受的答案也给了我一个过时的版本。
Here is another way to do it that works very well:
这是另一种非常有效的方法:
$ curl --silent --location https://rpm.nodesource.com/setup_12.x | bash -
$ yum -y install nodejs
You can also replace the 12.x with another version, such as 10.x, 8.x, etc.
您也可以将 12.x 替换为其他版本,例如 10.x、8.x 等。
You can see all available versions on the NodeSource Github page, and pull from there as well if desired.
您可以在NodeSource Github 页面上查看所有可用版本,如果需要,也可以从那里拉取。
Note: you may need to run using sudodepending on your environment.
注意:您可能需要sudo根据您的环境运行 using 。
回答by voltrevo
The accepted answer gave me node 0.10.36 and npm 1.3.6 which are very out of date. I grabbed the latest linux-x64 tarball from the nodejs downloads page and it wasn't too difficult to install: https://nodejs.org/dist/latest/.
接受的答案给了我非常过时的节点 0.10.36 和 npm 1.3.6。我从 nodejs 下载页面获取了最新的 linux-x64 tarball,安装起来并不难:https://nodejs.org/dist/latest/ 。
# start in a directory where you like to install things for the current user
(For noobs : it downloads node package as node.tgz file in your directlry)
curl (paste the link to the one you want from the downloads page) >node.tgz
Now upzip the tar you just downloaded -
现在将您刚刚下载的 tar 压缩 -
tar xzf node.tgz
Run this command and then also add it to your .bashrc:
运行此命令,然后将其添加到您的.bashrc:
export PATH="$PATH:(your install dir)/(node dir)/bin"
(example : export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")
(例如:export PATH ="$PATH:/home/ec2-user/mydirectory/node/node4.5.0-linux-x64/bin")
And update npm(only once, don't add to .bashrc):
并更新npm(仅一次,不要添加到.bashrc):
npm install -g npm
Note that the -gthere which means global, really means global to that npm instancewhich is the instance we just installed and is limited to the current user. This will apply to all packages that npm installs 'globally'.
请注意,-gthere 表示全局,实际上表示对那个 npm 实例是全局的,该实例是我们刚刚安装的实例,并且仅限于当前用户。这将适用于 npm '全局' 安装的所有包。
回答by goredwards
The procedure that worked for me (following theserather old instructions with a few updates):
对我有用的程序(遵循这些相当旧的说明并进行了一些更新):
- check git is installed
git --versionor install it via:sudo yum install git - install gcc and openssl:
sudo yum install gcc-c++ makesudo 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 nodegit checkout v6.1.0- put your desired version after thev./configuremakesudo make install - test that node is installed / working with either
node --versionor simplynode(exit node viaprocess.exit()or^Cx 2 or^C+exit) - check the npm version:
npm --versionand update if necessary viasudo npm install -g npm - Optional: remove the
nodedirectory withrm -r node
- 检查 git 是否已安装
git --version或通过以下方式安装:sudo yum install git - 安装 gcc 和 openssl:
sudo yum install gcc-c++ makesudo yum install openssl-devel - 将 git repo 克隆到一个名为
node(您可以稍后删除)的目录中:git clone https://github.com/nodejs/node.git - 在https://github.com/nodejs/node/releases决定你想要哪个版本的节点
- 转到刚刚创建的节点目录并安装节点
cd nodegit checkout v6.1.0- 将您想要的版本放在v./configuremakesudo make install - 测试该节点是否安装/使用
node --version或简单node(通过process.exit()或^Cx 2 或^C+退出节点exit) - 检查 npm 版本:
npm --version并在必要时通过更新sudo npm install -g npm - 可选:删除
node目录rm -r node
Notes:
笔记:
- The accepted answer didn't work since
sudo yum install nodejs --enablerepo=epel-testingreturns the error:No package nodejs available.
...andsudo 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 itselfsudo yum erase nodejssudo rm -f /usr/local/bin/node
(sudo yum rm nodejsin the accepted answer won't work asrmis not a valid yum command seeyum --help) - It's possible to clone the node repo via
git clone git://github.com/nodejs/node.gitrather thangit clone https://github.com/nodejs/node.gitbut you may get a various errors (see here). - If you already have a
/nodedir 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 - likesudo: npm: command not foundand/or have permissions issues installing node packages without sudo, editsudo nano /etc/sudoersand add:/usr/local/binto the end of the lineDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/binso that it readsDefaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
- 接受的答案不起作用,因为
sudo yum install nodejs --enablerepo=epel-testing返回错误:No package nodejs available.
...并且sudo yum install nodejs --enablerepo=epel(即没有-testing)只给出了非常旧的版本。 - 如果您已经安装了旧版本的节点,您可以使用以下命令将其删除:
sudo npm uninstall npm -g...因为 npm 可以自行卸载sudo yum erase nodejssudo rm -f /usr/local/bin/node
(sudo yum rm nodejs在接受的答案中将不起作用,因为rm它不是有效的 yum 命令,请参阅yum --help) - 可以通过
git clone git://github.com/nodejs/node.git而不是克隆节点存储库,git clone https://github.com/nodejs/node.git但您可能会收到各种错误(请参阅此处)。 - 如果您已经有
/node以前安装的目录,请在使用 git clone 命令之前将其删除(否则会发生冲突):rm -r node - 如果您在使用任何
sudo npm...命令时遇到问题- 像sudo: npm: command not found和/或在没有 sudo 的情况下安装节点包时遇到权限问题,请编辑sudo nano /etc/sudoers并添加:/usr/local/bin到行尾Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin,使其读取Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
回答by fuzzysearch
Simple install with NVM...
使用 NVM 简单安装...
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
To install a certain version (such as 12.16.3) of Node change the last line to
要安装某个版本(例如 12.16.3)的 Node,请将最后一行更改为
nvm install 12.16.3
For more information about how to use NVM visit the docs: https://github.com/nvm-sh/nvm
有关如何使用 NVM 的更多信息,请访问文档:https: //github.com/nvm-sh/nvm
回答by birnbaum
For the v4 LTS version use:
对于 v4 LTS 版本,请使用:
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum -y install nodejs
For the Node.js v6 use:
对于 Node.js v6 使用:
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
I also ran into some problems when trying to install native addons on Amazon Linux. If you want to do this you should also install build tools:
在尝试在 Amazon Linux 上安装本机插件时,我也遇到了一些问题。如果你想这样做,你还应该安装构建工具:
yum install gcc-c++ make
回答by troxwalt
I just came across this. I tried a few of the more popular answers, but in the end, what worked for me was Amazon's quick setup guide.
我刚遇到这个。我尝试了一些更受欢迎的答案,但最终,对我有用的是亚马逊的快速设置指南。
Tutorial: Setting Up Node.js on an Amazon EC2 Instance
The gist of the tutorial is:
本教程的要点是:
- Make sure you are ssh'd onto the instance.
- Grab nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash - Active
. ~/.nvm/nvm.sh - Install node using nvm
nvm install 4.4.5(NOTE: You can choose a different version. Check out the remote versions first by running$ nvm ls-remote) - Finally, test that you have installed node Node correctly by running
$ node -e "console.log('Running Node.js' + process.version)"
- 确保您已通过 ssh 连接到实例。
- 抓取 nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash - 积极的
. ~/.nvm/nvm.sh - 使用 nvm 安装节点
nvm install 4.4.5(注意:您可以选择不同的版本。首先通过运行查看远程版本$ nvm ls-remote) - 最后,通过运行测试您是否已正确安装节点 Node
$ node -e "console.log('Running Node.js' + process.version)"
Hopefully this helps the next person.
希望这有助于下一个人。
回答by theaws.blog
Seems no one is mentioning this. On Amazon Linux 2, official way to load EPEL is:
似乎没有人提到这一点。在Amazon Linux 2 上,加载 EPEL 的官方方法是:
sudo amazon-linux-extras install epel
sudo amazon-linux-extras install epel
...then you may:
...那么你可以:
sudo yum install nodejs
sudo yum install nodejs
回答by Brad W
I had Node.js 6.x installed and wanted to install Node.js 8.x.
我安装了 Node.js 6.x 并想安装 Node.js 8.x。
Here's the commands I used (taken from Nodejs's sitewith a few extra steps to handle the yum cached data):
这是我使用的命令(取自Nodejs 的站点,其中包含一些额外的步骤来处理 yum 缓存数据):
sudo yum remove nodejs: Uninstall Node.js 6.x (I don't know if this was necessary or not)curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -sudo yum clean allsudo yum makecache: Regenerate metadata cache (this wasn't in the docs, but yum kept trying to install Node.jx 6.x, unsuccessfully, until I issued these last two commands)sudo yum install nodejs: Install Node.js 8.x
sudo yum remove nodejs: 卸载Node.js 6.x(不知道有没有必要)curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -sudo yum clean allsudo yum makecache:重新生成元数据缓存(这不在文档中,但是 yum 一直尝试安装 Node.jx 6.x,但没有成功,直到我发出最后两个命令)sudo yum install nodejs: 安装 Node.js 8.x
回答by Xiao Peng - ZenUML.com
sudo yum install nodejs npm --enablerepo=epelworks for Amazon Linux AMI.
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
works for RedHat.
sudo yum install nodejs npm --enablerepo=epel为Amazon Linux AMI.
curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs
适用于 RedHat。

