Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up paths in Sublime with NVM

I am using NVM as my node version manager on OSX, which is great except that it creates multiple problems with my IDE. I am using Sublime Text and most of the plugins that I have ever used look for nodejs at /usr/local/bin and since I am using NVM node is obviously not available at that location, instead available at /Users/${User}/.nvm/${NodeVersion}/bin/node.

I have an option of updating the path of nodejs in that plugin's configuration but then when I install another plugin I have to do the same thing. Same applies to using CoffeeScript, LESScss etc.

Moreover when I update my node version via NVM, I have to update the paths in all the configs again. NVM has quite essentially created more problems while trying to solve one for me.

UPDATE: After a very long time I was able to finally resolve the problem using isaacs brilliant solution - nave. The nave usemain stable command, is just enough to understand you sentiments :)

like image 605
tusharmath Avatar asked Apr 18 '14 07:04

tusharmath


People also ask

How do I use NVM specific Node?

Switching among Node. 7; we can simply run either nvm use 12.22. 7 or nvm use 16.13. 0 to easily switch into either version we need. Note that since we only have one version that begins with 12, 14, or 16, we can switch versions with a simple nvm use 16 , nvm use 14 , or nvm use 12 command.

How do I set global Node to NVM?

Just type nvm alias default v10. 16.3 in your terminal and then type nvm use default . This command will make v10. 16.3 available in any shell you open — you just have to restart your terminal to make sure it works.

Can Sublime Text run node JS?

Yes, Sublime Text provides support for Node. js. So we can run nodejs app in Sublime Text.


3 Answers

I was having a similar problem yesterday. I found a python script that exports my Node path (the nvm node path) for Sublime. I updated it for OSX and ST3. You can find it here: https://gist.github.com/joesepi/11269417

Drop that script in your Packages dir, the path for ST3 is in the comments in the script. You may have to restart ST as well. And if you update your node version, you will need to update that script too. I hope that helps!

like image 59
joe sepi Avatar answered Sep 22 '22 18:09

joe sepi


New Answer for 2020!

You can now add the following one-liner to your .bashrc, .zshrc, etc.

export NVM_SYMLINK_CURRENT=true 

Then, anywhere you need your node path, it's always in the same place:

~/.nvm/current/bin/node  #OR  $HOME/.nvm/current/bin/node  


Further reading: https://medium.com/@danielzen/using-nvm-with-webstorm-or-other-ide-d7d374a84eb1

like image 36
undefined Avatar answered Sep 20 '22 18:09

undefined


you can use command "nvm which node-version " such as

nvm which 0.12.0
like image 23
Azadious Avatar answered Sep 22 '22 18:09

Azadious