无法从 bash 脚本使用 nvm [英] Can't use nvm from bash script

查看:99
本文介绍了无法从 bash 脚本使用 nvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 shell 脚本来自动化我的开发环境设置(安装 python、nvm、node、mongo 等...).我正在使用 nvm 安装节点.它告诉您关闭并重新打开终端以开始使用 nmv 命令.我尝试获取 .bashrc 和 .profile 以立即使命令可用,以便我可以继续使用 nvm install 运行脚本,但它不起作用.

I am trying to write a shell script to automate my dev environment set-up (install python, nvm, node, mongo etc...). I am using nvm to install Node. It tells you to close and reopen your terminal to start using the nmv command. I tried to source .bashrc and .profile to make the command available right away so I can continue running the script with nvm install, but it doesn't work.

这是我的脚本中与安装 NVM/Node 相关的部分:

Here is the segment of my script related to installing 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.它只是在脚本中不起作用.

I get these messages, but please note that I've already run the script and NVM / Node are already installed and working. I can also use nvm and node in the same terminal I run the script from after it completes. It just doesn't work in the script.

=> 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

推荐答案

如果你在主shell上运行了nvm,你只需要添加:

if you have nvm running on the main shell, you just need to add:

export NVM_DIR=$HOME/.nvm;
source $NVM_DIR/nvm.sh;

在你的脚本中

这篇关于无法从 bash 脚本使用 nvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆