1

I tried to install n for node version updates following this answers direction. It was successful in upgrading me to node v7 but had a side effect. Node is now found:

/usr/local/bin/node 

If I type node -v I get a bash error because it's looking in the wrong place (it looks in usr/bin/node). What is my best path forward? How do I change the path where my terminal looks for node so I can run node index.js while not interfering with my desire to use n to upgrade node in the future.

I'm not sure if this is relevant but, when I'm in a project and I type nodemon index.js everything works as expected. I think that this is due to the fact that nodemon is installed where node v7 is installed.

Here is the value of echo $PATH:

    /usr/local/heroku/bin:/home/devin/.rbenv/shims:/home/devin/.rbenv/bin:/usr/bin:/home/devin/bin:/home/devin/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Here is the value of which node:

/usr/local/bin/node

The value of locate node overloads the terminal and ends like this:

    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/node.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/outer_join.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/over.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/regexp.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/right_outer_join.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/select_core.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/select_statement.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/sql_literal.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/string_join.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/table_alias.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/terminal.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/true.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/unary.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/unary_operation.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/unqualified_column.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/update_statement.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/values.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/window.rb
    /var/lib/gems/2.3.0/gems/arel-7.1.2/lib/arel/nodes/with.rb
    /var/lib/gems/2.3.0/gems/execjs-2.7.0/lib/execjs/support/node_runner.js
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node.c
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node.h
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node.o
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node_set.c
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node_set.h
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/ext/nokogiri/xml_node_set.o
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/css/node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/xml/node
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/xml/node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/xml/node_set.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/xml/node/save_options.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/xml/pp/node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/html/test_node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/html/test_node_encoding.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/node
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node_attributes.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node_encoding.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node_inheritance.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node_reparenting.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_node_set.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/test_unparented_node.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/node/test_save_options.rb
    /var/lib/gems/2.3.0/gems/nokogiri-1.6.8/test/xml/node/test_subclass.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/script/tree/node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/at_root_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/charset_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/comment_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/content_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/css_import_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/debug_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/directive_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/each_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/error_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/extend_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/for_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/function_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/if_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/import_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/keyframe_rule_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/media_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/mixin_def_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/mixin_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/prop_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/return_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/root_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/rule_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/supports_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/trace_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/variable_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/warn_node.rb
    /var/lib/gems/2.3.0/gems/sass-3.4.22/lib/sass/tree/while_node.rb
  • What's the output of echo $PATH and which node and locate node Thank you for helping us help you! – Elder Geek Feb 9 '17 at 20:57
  • @ElderGeek I've updated the question with the answer to your request. Thanks! – aisflat439 Feb 9 '17 at 21:00
  • Thank you for that. I'd still like to see the output of the other 2 commands as well. – Elder Geek Feb 9 '17 at 21:02
  • @ElderGeek Thanks much for your questions. I believe those questions helped the other user answer the question. I selected his answer as correct. Thanks again. – aisflat439 Feb 10 '17 at 1:08
  • Glad to help. That was my intent and I'm glad it worked out. – Elder Geek Feb 10 '17 at 13:53
3

You need to add another PATH to your environment variables.

In case this is the first time you've had to do this, I'll try to explain the logic behind what to do.

Whenever you run a command, your terminal shell will try to run the first word. Your shell has a PATH environment variable list where it will check for the command you run (e.g. node) by going through the list of paths it knows until it finds it. You can check what your PATH is by typing in the Terminal:

echo $PATH

The file's path (i.e. /usr/local/bin/ of /usr/local/bin/node) is likely not on the list. The different paths are separated by colons, showing something like this:

/home/user/bin:/home/user/.local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Appending the file's path (/usr/local/bin/) to your shell's PATH in its rc file should be enough. A shell rc file is a 'runcom' file which literally means 'run commands' when the shell instance starts. In bash, it's located at ~/.bashrc. If you use something else, you'll need to look up what it is, like for zsh it's ~/.zshrc.

Open the file and on the line that looks something like export PATH="...$PATH" and add a :/usr/local/bin/ to the end of it.

It may look something like this:

export PATH="[other paths]:$PATH:/usr/local/bin"

If you don't have a line like that anywhere in the file, just add a new line with this:

export PATH="$PATH:/usr/local/bin"

Save the rc file and close and re-open your terminal and you'll be able to use node as a command. You should also be able to see the new path added when running echo $PATH.

  • Thanks very much for this clear answer. I've messed around with paths a few times but never with a high level of confidence. This answer clearly solved my issue and I feel equipped to handle similar issues in the future. – aisflat439 Feb 10 '17 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.