3

Definitely a noob question so please don't judge but this has been bothering me for a while.

No more how many times I run $ sudo npm install -g express-generator or $ npm install express -g, everything seems to install but the command $ express still doesn't exist.

I'm running fish shell. Also, I'm assuming this is an issue coming from my PATH file, but I'm lost on if that's .bash_profile or .bashrc.

My .bash_profile has the three lines in it:

  export PATH=/usr/local/bin:$PATH
  export PATH=/Users/username/.node/lib/node_modules/express-generator/bin/express:$PATH
  export PATH=/Users/username/.node/bin/express:$PATH

and my .bashrc file has nothing regarding node in it.

When express installs, it returns:

  /Users/username/.node/bin/express -> /Users/username/.node/lib/node_modules/express-generator/bin/express
  /Users/username/.node/lib 

but when I command which node it returns

/usr/local/bin/

When I try to run $ls -l /usr/local/bin/express it returns:

ls: /usr/local/bin/express: No such file or directory

Cannot find the diagnosis of why the express command won't work after installation.

  • Q: `node` and `npm` both work from the command line, correct? Q: Could you please update your post with the output for this command: `ls -l /usr/local/bin/express`? Q: Is there an error message? If so, please copy/paste the exact text into your post. – paulsm4 Jun 04 '16 at 03:10
  • updated with what is returned that command – fullwackdeveloper Jun 04 '16 at 03:13
  • 1
    OK: 1) Q: What happens with `express-generator`, and `which express-generator`? 2) Please look at this thread: [Express command not found](http://stackoverflow.com/questions/23002448/express-command-not-found) – paulsm4 Jun 04 '16 at 03:14
  • @paulsm4 I tried everything in that link and have not found a solution yet. Running `$ which express-generator` yields `which: no express-generator in (/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/go/bin)` – fullwackdeveloper Jun 04 '16 at 03:16
  • Please clarify which shell you are using. What does `echo $SHELL` output? I'm confused because you talk about .bashrc and .bash_profile which are not relevant if you're using fish. – Kurtis Rader Jun 04 '16 at 16:53
  • It's written in the post I'm using fish shell :) – fullwackdeveloper Jun 04 '16 at 23:08
  • @paulsm4 `ls: /usr/local/bin/express: No such file or directory` – prakashchhetri Jun 20 '18 at 15:18

2 Answers2

2

If you are running fish, your .bash_profile is ignored, of course!

The preferred way to add /Users/username/.node/bin/ to your $PATH in fish is like so:

set -U fish_user_paths $fish_user_paths /Users/username/.node/bin/

that's just something you run once, at the command line - not something you put in a startup file.

If you prefer to use startup files, you can instead modify your ~/.config/fish/config.fish like so:

set PATH $PATH /Users/username/.node/bin/
ridiculous_fish
  • 17,273
  • 1
  • 54
  • 61
  • I did both of these, and they won't work. However, when I `echo $PATH`, I get: `/usr/local/bin /Users/username/.node/bin/` `/usr/sbin` `/usr/local/bin` `/usr/bin ` `/bin` `/usr/sbin` `/sbin` `/opt/X11/bin` `/usr/local/go/bin` `/Users/[myusername]/.node/bin` Isn't this too many? Also how do I remove the `/Users/username/.node/bin/` from my $PATH? – fullwackdeveloper Jun 04 '16 at 23:50
  • It is very surprising that `/Users/username/.node/bin/` would be in $PATH but `express` would not be found. Does the file `/Users/username/.node/bin/express` actually exist? To be sure, username was meant to be replaced with your actual username of course. – ridiculous_fish Jun 06 '16 at 18:09
  • If you added that path element via fish_user_paths, you could just write `set -e fish_user_paths[1]` to remove it. – ridiculous_fish Jun 06 '16 at 18:10
1

From the symlink after the install, the express binary should be available in the /Users/username/.node/bin directory. The reason you can't use the binary is because the /Users/username/.node/bin directory is not in your $PATH. Whats in the $PATH is the binary itself.

When you add a directory to your $PATH, you can execute binaries from within the directory. Currently, your $PATH points to the /Users/username/.node/bin/express which does not have any binaries within it. You should correct it to:

export PATH=/Users/username/.node/bin:$PATH
gnerkus
  • 11,357
  • 6
  • 47
  • 71
  • followed this advice and it still won't quite work. tried commanding `$ echo $PATH ` and it returns: `/usr/local/bin /Users/username/.node/bin/` `/usr/sbin` `/usr/local/bin` `/usr/bin ` `/bin` `/usr/sbin` `/sbin` `/opt/X11/bin` `/usr/local/go/bin` `/Users/[myusername]/.node/bin` Isn't this too many? Would you know how I can remove the `/Users/username/.node/bin/` from my $PATH? – fullwackdeveloper Jun 04 '16 at 23:54