[英]Node and NPM path in OSX
I have a very strange configuration issue.我有一个非常奇怪的配置问题。
When logging to machine (SSH session) and executing the following commands using interactive shell, they succeed:当登录到机器(SSH 会话)并使用交互式 shell 执行以下命令时,它们会成功:
node --version
npm --v
However, when I execute the following through script from remote machine:但是,当我从远程机器通过脚本执行以下操作时:
#!/bin/bash
#Script input arguments
user=${1}
server=${2}
#Tell the shell to quote your variables to be eval-safe!
printf -v user_q '%q' "$user"
printf -v server_q '%q' "$server"
#
# Script variables
address="$user_q"@"$server_q"
#
function run {
ssh "$address" /bin/bash "$@"
}
run << SSHCONNECTION
node --version
npm --v
exit
SSHCONNECTION
I get the following output:我得到以下输出:
/bin/bash: line 2: node: command not found
/bin/bash:第 2 行:节点:找不到命令
/bin/bash: line 3: npm: command not found
/bin/bash:第 3 行:npm:找不到命令
I am conscious that the issue may be the in .bash_profile file configuration我意识到问题可能出在 .bash_profile 文件配置中
export PATH="/usr/local/bin/npm:/usr/local/bin/node:/usr/local/bin:$PATH"
Also, here is result of npm config get prefix
:此外,这是
npm config get prefix
的结果:
/usr/local
/usr/本地
Can you please suggest what I am doing wrong?你能建议我做错什么吗?
I believe what happened is due to the fact .bash_profile
is only executed when bash is invoked for an interactive shell, more info about this here: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#Bash-Startup-Files我相信发生的事情是因为
.bash_profile
仅在为交互式 shell 调用 bash 时才执行,有关此的更多信息在这里: https ://www.gnu.org/software/bash/manual/html_node/Bash-Startup -Files.html#Bash-启动-文件
When invoking and passing the script directly to /bin/bash, it will behave as a non-interactive shell which the default behaviour to not read the .bash_profile
.当调用脚本并将其直接传递给 /bin/bash 时,它将表现为一个非交互式 shell,默认行为是不读取
.bash_profile
。
I would suggest setting you PATH variable in /etc/environment
so it will take affect for all users and all manners of scripting.我建议您在
/etc/environment
中设置 PATH 变量,以便它对所有用户和所有脚本编写方式产生影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.