在travis上的R容器上安装特定节点版本

Installing specific node version on R container on travis

因为我用的是Netlify CLI tools on travis, I need to have a node version above 8 but the R container I use only has 6.12 according to the error message. I saw that it is possible to specify the node version for java script projects and there is an answer for here on Whosebug, but I tried both and they did not work for my case. What is the proper way of installing a specific node version in an arbitrary travis container such that other applications can access it ? Or maybe even better, (how) can I make npm satisfy the minimal version dependency on node when installing the Netlify CLI tools? I have no prior experience with npm. You can find the version history of my .travis file here.

To install Netlify CLI, make sure you have Node.js version 8 or higher

基于 Netlify 的文档 here

Travis 的最快解决方案

Optionally, your repository can contain a .nvmrc file in the repository root to specify which single version of Node.js to run your tests against.

quote from the docs 说要将 .nvmrc 文件添加到项目的根目录,版本为

.nvmrc

8.14.0

注意:将版本替换为与您的项目兼容且满足所有要求的版本。此外,仅当 .travis.yml 文件中的 node_js 键未指定 nodejs 版本时,才会读取 .nvmrc 文件。

根据@talves 提供的解决方案,我发现我可以修改 before_script 步骤来安装特定版本的节点,例如8.14:

before_script:
- nvm install 8.14
- npm install -g netlify-cli
- Rscript -e 'blogdown::install_hugo()'

因为已经安装了 nvm 和 npm。要安装最新的稳定版本,请将上面的 8.14 替换为 node。这样,我就不需要 .nvmrc 文件了。