简体   繁体   English

在tmux会话中使用nvm管理多个Node.js版本

[英]Managing multiple Node.js versions with nvm in a tmux session

Short question 简短的问题

How can I get nvm to work with tmux ? 如何使nvmtmux一起使用

Path Problems 路径问题

As MarkHu surmised in his answer , the problem is related to the PATH. 作为MarkHu在猜测他的答案 ,这个问题是关系到PATH。 Below is a comparison of the path in bash before entering tmux and after starting tmux . 下面是bash进入tmux之前和启动tmux之后的路径的比较。 (I replaced each : in the path with a line break to make it easier to compare.) (我将换行符替换为路径中的每个:,以便于比较。)

Bash和tmux PATH比较

Now I'm curious as to: 现在我很好奇:

  1. Why are /usr/local/sbin and /Users/matthew/bin are duplicated in the path? 为什么/usr/local/sbin/Users/matthew/bin在路径中重复?
  2. Why did /Users/matthew/.nvm/v0.11.5/bin along with /usr/local/sbin and /Users/matthew/bin get moved to the end of the path? 为什么/Users/matthew/.nvm/v0.11.5/bin以及/usr/local/sbin/Users/matthew/bin移到路径的末尾?

Background 背景

I'm running OS X 10.8.4 Mountain Lion. 我正在运行OS X 10.8.4 Mountain Lion。 I installed tmux v1.8 and Node.js using: 我使用以下命令安装了tmux v1.8和Node.js

brew install tmux
brew install node

I then decided I wanted to manage multiple node version, so I installed nvm using: 然后,我决定要管理多个节点版本,因此我使用以下命令安装了nvm

curl https://raw.github.com/creationix/nvm/master/install.sh | sh

If I'm not in a tmux session, nvm appears to work correctly. 如果我不在tmux会话中,则nvm似乎可以正常工作。 When I start a tmux session though, it finds the Node.js installed by Homebrew instead of using the nvm version. 但是,当我启动tmux会话时,它将找到由Homebrew安装的Node.js ,而不是使用nvm版本。 Any thoughts on how to get nvm to work with tmux ? 关于如何使nvmtmux一起使用的任何想法?

$ which node
/Users/matthew/.nvm/v0.11.5/bin/node
$ tmux
$ which node
/usr/local/bin/node
$ nvm use v0.11.5
Now using node v0.11.5
$ which node
/usr/local/bin/node 

Check your $PATH environment var before and after. 前后检查您的$ PATH环境变量。

There is a difference between setting it in ~/.bash_profile and ~/.bashrc depending on how you have those configured. 根据您的配置方式,在〜/ .bash_profile和〜/ .bashrc中进行设置之间存在差异。

Also, you may want to read https://unix.stackexchange.com/questions/15453/using-environment-variables-in-tmux-conf-files if you think other node.js-related vars may need to be set. 另外,如果您认为可能需要设置其他与node.js相关的变量,则可能需要阅读https://unix.stackexchange.com/questions/15453/using-environment-variables-in-tmux-conf-files

I just run: 我只是跑:

nvm deactivate
nvm use x.x

That seems to work. 这似乎有效。 You can script out the needed version depending on the project you're working on. 您可以根据正在处理的项目来编写所需版本的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM