我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。
如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?
我已经看到了使用yum安装依赖项,然后从源代码安装Node.JS和NPM的文章。虽然这是可行的,但我觉得Node.JS和NPM都应该在公共回购的某个地方。
如何在AWS亚马逊Linux上一个命令安装Node.JS和NPM ?
当前回答
正如其他人提到的,使用epel会得到一个非常过时的版本,下面是我刚刚写的一个小脚本,它可以添加到CI管道中,或者将其传递给ec2 user-data,以安装最新版本的node,只需将版本替换为您想要的版本,以及您正在使用的合适的Linux发行版。
下面以amazon-Linux-2-AMI为例
#!/bin/bash
version='v14.13.1'
distro='linux-x64'
package_name="node-$version-$distro"
package_location="/usr/local/lib/"
curl -O https://nodejs.org/download/release/latest/$package_name.tar.gz
tar -xvf $package_name.tar.gz -C $package_location
rm -rfv $package_name.tar.gz
echo "export PATH=$package_location/$package_name/bin:\$PATH" >> ~/.profile
如果您想在同一个shell中测试它,只需运行即可
. ~/.profile
其他回答
您可以通过重新安装已安装的包到当前版本来更新/安装节点,这可能会使我们在进行更新时避免大量错误。
这是由nvm使用下面的命令完成的。在这里,我已经将我的节点版本更新到8,并将所有可用的包重新安装到v8 !
nvm i v8 --reinstall-packages-from=default
它也可以在AWS Linux实例上工作。
如官方文件所述,简单以下2步-
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -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
RHEL、CentOS、CloudLinux、Amazon Linux、Fedora:
# As root
curl -fsSL https://rpm.nodesource.com/setup_12.x | bash -
# No root privileges
curl -fsSL https://rpm.nodesource.com/setup_12.x | sudo bash -
sudo yum install -y nodejs
正如其他人提到的,使用epel会得到一个非常过时的版本,下面是我刚刚写的一个小脚本,它可以添加到CI管道中,或者将其传递给ec2 user-data,以安装最新版本的node,只需将版本替换为您想要的版本,以及您正在使用的合适的Linux发行版。
下面以amazon-Linux-2-AMI为例
#!/bin/bash
version='v14.13.1'
distro='linux-x64'
package_name="node-$version-$distro"
package_location="/usr/local/lib/"
curl -O https://nodejs.org/download/release/latest/$package_name.tar.gz
tar -xvf $package_name.tar.gz -C $package_location
rm -rfv $package_name.tar.gz
echo "export PATH=$package_location/$package_name/bin:\$PATH" >> ~/.profile
如果您想在同一个shell中测试它,只需运行即可
. ~/.profile