部署时关于 Node 版本问题

周末抽时间把个人项目的 Rails 版本从 5.2.1 升级到 5.2.2

更新 rails version in Gemfile,然后运行 bundle update

升级结束后,本地一切正常。然后就打算部署到服务器上。当运行 bundle exec cap production deploy 时,结果无法部署.

Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host xxxxx.com: rake exit status: 137
yarn install v1.10.1
warning You are using Node "4.2.6" which is not supported and may encounter bugs or unexpected behavior. Yarn supports the following semver range: "^4.8.0 || ^5.7.0 || ^6.2.2 || >=8.0.0"
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
success Already up-to-date.

从这个错误信息中,我么可以明显看出时因为 Node 版本的太低 (4.2.6).

接下来,我们需要找到 node 的源,然后更新更新一下 Node.  具体的实施步奏如下:

1. 查看服务器当前系统型号

user@icmoc.com:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.4 LTS
Release:	16.04
Codename:	xenial

2. 寻找源 - https://www.ubuntuupdates.org/ppa/nodejs_6.x?dist=xenial

3. 添加源,更新,升级node

$ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
$ sudo sh -c "echo deb https://deb.nodesource.com/node_6.x xenial main \
> /etc/apt/sources.list.d/nodesource.list"
$ sudo apt-get update
$ sudo apt-get install nodejs

4. 查看是否升级成功

user@icmoc.com:~$ node --version
v6.16.0

看起来可以了。

最后,重新部署一次。OK了!