29

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 :)

tusharmath
  • 10,622
  • 12
  • 56
  • 83
  • 1
    Had same issue. just set `nvm alias default `. from this answer http://stackoverflow.com/a/34777308/1446728 – Femi Oni Feb 18 '17 at 21:40
  • @FemiOni – I have done this, but the issue in SublimeText remains the same. It looks for node in `/usr/bin/local/` and obviously doesn't find the executable there. Could you expalin what how `nvm alias default 14.1.0` should change this? – katerlouis Jan 31 '21 at 14:37
  • @tusharmath – (sorry, noob here) – so basically `nave` replaced `nvm` in your setup? Or did you run them side by side? And why is `nave usemain stable` working for you? After doing that my `/usr/local/bin` still doesn't have a node file. – katerlouis Jan 31 '21 at 14:44
  • @tusharmath in order for that to work, did you have to uninstall `nvm` completely? – katerlouis Jan 31 '21 at 15:39

8 Answers8

12

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

undefined
  • 740
  • 9
  • 17
  • That's a great solution! However please mind that in order to use it you must first activate `nvm` by typing something like `nvm use [VERSION]` in terminal (otherwise the symbolic links won't work). – stratis Feb 05 '22 at 20:14
  • That's not entirely true, assuming one has followed the documentation and properly set up the rest of the installation. NVM does have a default installation that it will fall back to. `nvm use` will switch to a specific non-default version. – undefined Apr 27 '22 at 19:05
9

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!

joe sepi
  • 579
  • 1
  • 4
  • 9
  • 1
    this did the job for me as well, thanks! I made a few improvements to the script so it becomes a drop-in for everyone and references the current nvm 'default' alias – Felix Müller Jun 27 '14 at 14:05
3

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

nvm which 0.12.0
Azadious
  • 162
  • 2
  • 10
  • 1
    Example should be `nvm which 0.12.0` not `node which 0.12.0` – Claudijo Mar 02 '15 at 19:55
  • 6
    This doesnt solve anything. This just gives you the path of the node you are using. He already knows that. – Craicerjack Nov 18 '15 at 11:11
  • I tried `nave` but it doesn't appear to work, so this helped me find the path at least and change the settings for the installed package. If I find myself having to do this repeatedly, I guess I'll make the `nave` solution work. – Yorick Nov 16 '16 at 15:36
0

Install NVM from github.com/xtuple/nvm

Run this command to install NVM as global and you'll see everything works fine

wget -qO- https://raw.githubusercontent.com/xtuple/nvm/master/install.sh | sudo bash

Ghominejad
  • 1,572
  • 16
  • 15
0

I'm using n. I also tried nave but I was having trouble with it with nvm installed. Hope this helps.

JohnnyQ
  • 4,839
  • 6
  • 47
  • 65
0

For Linux users,

By default nvm write some node paths in your .bashrc and there are loaded only if you’r in bash mode.

So just you need to move the two paths-line to the bottom on the file like that :

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# Set the NVM path for my Sublime before return.
export NVM_DIR="/home/<yourUser>/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

# If not running interactively, don't do anything
[ -z "$PS1" ] && return
4sStylZ
  • 36
  • 6
0

CURRENT_NODE_VERSION=$(nvm current); nvm which $CURRENT_NODE_VERSION

Devin M
  • 539
  • 5
  • 14
0

I am using ubuntu 18 and this was how i was able to solve it

open your command prompt and access /home/{username}/.config/sublime-text-3/Packages create a new file and put this code

# $HOME/.config/sublime-text-3/Packages/node-env.py

import os
import getpass

nvm_path = '/home/%(user)s/.nvm' % {'user': getpass.getuser()}
nvm_default_file_path = '%(root)s/alias/default' % {'root': nvm_path}
nvm_node_root = '%(root)s/versions/node' % {'root': nvm_path}

# Grab default alias
with open(nvm_default_file_path, 'r') as content_file:
   content = content_file.read()

# Prepend 'v' to match folder names
version = content.strip()
if version[0] != 'v':
version = 'v' + version

# Take highest valid folder name
versions = os.listdir(nvm_node_root)
found = sorted([v for v in versions if v.startswith(version)])[-1]

if found == None:
  print("Failed to configure node: no valid version found for %(version)s" %{'version': version})
else:
  print("Configure node: %(version)s" % {'version': found})
  node_path = "%(root)s/%(version)s" % {'root': nvm_node_root, 'version': found }
  print("Node path: %(root)s" % {'root': node_path})
  path = "%(root)s/bin:%(root)s/lib:%(path)s" % {'root':node_path,'path':os.environ["PATH"]}
  os.environ["PATH"] = path

save this file as "node-env.py".

It helps solve issues with most JavaScript libraries like Typescript plugging and others.

Miracool
  • 657
  • 6
  • 7