26

I am studying RoR and I am setting this virtual machine to "deploy" RoR and I got stuck in the Node.js installation.

I am using Ubuntu 12.04 and I followed this step of this guide:

http://railsapps.github.com/installing-rails.html

Since Rails 3.1, a JavaScript runtime has been needed for development on Ubuntu Linux (it is not needed for Mac OS X or Windows). For development on Linux Ubuntu, it is best to install the Node.js server-side JavaScript environment:

$ sudo apt-get install nodejs

and set it in your $PATH.

What does it mean, "set to my $PATH"?

I've been searching for it on google in the last couple of hours and all solutions are different, for different problems and I get no simple answer for that. Can you give a little light here?

Thanks!

4 Answers 4

31

You don't have to worry about that, the apt-get install command will do that for you. It adds the path to the nodejs process (usually /usr/bin/node) to the global $PATH variable. This ensures that when you type node in your terminal it will start the nodejs process.

If for some weird reason you cannot start it, you'll have to manually add the path to your node installation to the $PATH. You can do this by editing your ~/.bashrc file and adding:

PATH=/usr/bin/node:$PATH
4
  • 2
    Which assumes the OP is using bash. ;-)
    – Rob Raisch
    Commented Nov 6, 2012 at 20:55
  • 4
    you also need to reload bash.rc source ~/.bashrc
    – maahd
    Commented Oct 13, 2015 at 8:07
  • ~/.bashrc command isn't working in ubuntu. How can I edit this Commented Jun 20, 2021 at 20:08
  • /usr/local/bin/node this is my node path. If I change the path to /usr/bin/node then my problem was solved? Commented Jun 20, 2021 at 20:19
17

I've been trying to install npm and it has complained about node not being in the path. Funnily enough, nodejs was, but node wasn't. I ended up solving the problem thus:

$ cd /usr/bin/
$ sudo ln -s nodejs node

...which symlinks node to nodejs. Now npm installs without complaints.

2
  • 5
    This was required in UBuntu 16.04 after installing with apt-get. Thank you. :-) Commented Nov 2, 2016 at 8:33
  • Also on Ubuntu 16.04, did this, fixed the node issue but now npm isn't recognized anymore
    – DFSFOT
    Commented Jun 4, 2021 at 14:19
1

Depending on which shell you are running, the answer may be different, but a good starting place might be http://www.troubleshooters.com/linux/prepostpath.htm

And http://www.linuxjournal.com/article/3645

1
  • In order for your answer to be ideal, you should summarize the main points of those links because they may be dead in the future. Thanks for the links, in any case.
    – airstrike
    Commented Sep 1, 2015 at 2:29
1

I restarted Ubuntu after the install. That fixed the issue for me.

1
  • Could you specify the Ubuntu version you're using?
    – codemonkey
    Commented Dec 7, 2020 at 5:50

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