我正在尝试编写一个shell脚本来自动化我的开发环境设置(安装python、nvm、node、mongo等)。我正在使用nvm安装Node。它告诉您关闭并重新打开终端以开始使用nmv命令。我尝试获取.bashrc和.profile的源代码,以使该命令立即可用,这样我就可以继续使用nvm install运行该脚本,但它不起作用。
以下是我的脚本中与安装NVM /Node相关的部分:
#install nvm and latest node version
# sourcing profile and bashrc is not working here. nvm does not execute the next two lines to install node.
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
source ~/.profile
source ~/.bashrc
nvm install 5.0
nvm alias default node我收到了这些消息,但请注意,我已经运行了脚本,并且NVM / Node已经安装并正常工作。在脚本运行完成后,我还可以在运行脚本的同一终端中使用nvm和node。这在脚本中是行不通的。
=> Downloading nvm from git to '/home/myDir/.nvm'
=> fatal: destination path '/home/myDir/.nvm' already exists and is not an empty directory.
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
=> Source string already in /home/myDir/.bashrc
=> Close and reopen your terminal to start using nvm
./install-programs.sh: line 27: nvm: command not found
./install-programs.sh: line 28: nvm: command not found发布于 2017-07-29 09:48:26
如果您在主shell上运行nvm,则只需添加:
export NVM_DIR=$HOME/.nvm;
source $NVM_DIR/nvm.sh;在你的脚本中
发布于 2016-04-12 09:33:24
以下是对我起作用的方法。
首先使用SSH或控制台安装nvm (一次性和单独):
$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash然后在脚本中,加载您的配置文件,如下所示:
. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc幸运的是,nvm应该可以在脚本中使用。
nvm install 4.4.2塔达!
发布于 2020-02-14 02:33:34
只需将此代码放在您的脚本之上:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion在这里起到了很好的效果。
https://stackoverflow.com/questions/35206723
复制相似问题