我的CentOS 7.4上有节点v6.12.2。但是我必须保留v6.9.1,所以当我按照它工作时,但是在重新启动或注销之后,它就不保存了。
sudo yum install epel-release
sudo yum install nodejs
sudo yum install npm
npm install forever -g
curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash
source ~/.bash_profile
nvm list-remote
nvm install v6.9.1
# nvm use 6.9.1
Now using node v6.9.1发布于 2018-01-09 14:44:12
nvm alias default 6.9.1
根据NVM文档
若要设置在任何新shell中使用的默认节点版本,请使用别名
default: nvm别名默认节点
注意,这会将最新版本设置为默认值.
所以在你的情况下,你会:
# Install the version that you would like
nvm install 6.9.1
# Set 6.1.0 (or another version) as default
nvm alias default 6.9.1在不同版本下运行不同的应用程序
或者,如果您需要为服务器上的不同应用程序使用不同的版本,您可以在crontab文件中使用如下内容:
@reboot forever start -c /home/your-name/.nvm/versions/node/v6.9.1/bin/node /path/to/app1/server.js
@reboot forever start -c /home/your-name/.nvm/versions/node/v0.11.0/bin/node /path/to/retro/app/server.js
@reboot forever start -c /home/your-nodenode /path/to/modern/app/server.js就我个人而言,这是我最喜欢的方法,就好像您有20或30个节点应用程序一样,更容易指定自己的版本,而不只是依赖服务器当前的版本。
发布于 2018-01-09 15:17:14
工作!CentOS 7.4
第一步
从新到旧。
curl https://raw.githubusercontent.com/creationix/nvm/v0.13.1/install.sh | bash
source ~/.bash_profile
nvm list-remote
nvm install v6.7.0
nvm use 6.7.0
Now using node v6.7.0
nvm alias default 6.7.0
whereis node
node: /usr/bin/node /usr/share/node /root/.nvm/v6.7.0/bin/node /usr/share/man/man1/node.1.gz
/root/.nvm/v6.7.0/bin/node --version
v6.7.0第二步
以服务的方式运行。
cat /etc/systemd/system/node-server1.service
[Unit]
Description=Node-Server1
#Requires=After=mysql.service # Requires the mysql service to run first
[Service]
ExecStart=/root/.nvm/v6.7.0/bin/node /home/www/html/server.js
Restart=always
RestartSec=1 # Restart service after 10 seconds if node service crashes
StandardOutput=syslog # Output to syslog
StandardError=syslog # Output to syslog
SyslogIdentifier=nodejs-server1
#User=<alternate user>
#Group=<alternate group>
Environment=NODE_ENV=production PORT=1337
[Install]
WantedBy=multi-user.target第三步
systemctl enable node-server1.service
systemctl start node-server1.service
tail -f /var/log/messageshttps://stackoverflow.com/questions/48170267
复制相似问题