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.
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/
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
Related
On RHEL I have put various executable files in ~/.local/bin eg. nvim.appimage. As ~/.local/bin is in my $PATH variable I can call nvim.appimage from any directory which is great.
I want some node apps to be able to be called from any directory, for example ESLint. These are not binaries but are directories with a lot of files and directories inside. Which directory (presumably in $PATH) should they be in so that I as a user but not other users can call them from any of my directories? Also how should they be invoked.
As an example, I have put the cowsay node app into ~/.local/bin I can invoke it like this from any of my directories:
$ node ~/.local/bin/cowsay/node_modules/cowsay/cli.js moo
(I can actually omit node from that command as cli.js has #!bin/bash/env node at the top.)
I would like to be able to invoke cowsay from any of my directories with a simple command eg cowsay
I know that a lot of node apps are not intended to be run from the command line but some are. In particular I am having great difficulty to get neovim with Ale to recognize some node linters like ESLint. Perhaps if I can sort the cowsay issue out I may be able to move on to ESLint with neovim. I am hoping that if I can get ESLint invokable from a location in $PATH it might be usable by neovim / Ale.
Can this achieve what you expected ?
mkdir ~/.local/nodexe
cd ~/.local/nodexe
ln -fs ../bin/cowsay/node_modules/cowsay/cli.js cowsay
PATH=$PATH:~/.local/nodexe
Assuming you have #!bin/bash/env node in cli.js, then you can run by typing cowsay moo
I'm a linux / ubuntu / node newbie. I am running ubuntu 16.04 on a virtual private web server. It's running nodejs & everything is running well.
But when I run a global module/package from the command line, I write it like so:
node /usr/local/bin/forever start /usr/local/bin/http-server /var/www/myWebsite -p 8000
Which works fine. But you'll notice in node I have to specify the full path to my globally installed module/package (/usr/local/bin/)
My question: Is there a way I can run a global node module/package without specifying the full path?
EG., instead of writing:
node /usr/local/bin/forever // forever is a globally installed module
Can I make it so I can write:
node forever // forever is a globally installed module
I have tried editing my ~./bashrc file to include a NODE_PATH like so
nano ~/.bashrc
# added line at bottom of bashrc file
NODE_PATH=/usr/local/bin
But no luck. Also, when I run echo $NODE_PATHI get:
/usr/local/bin
Which is the correct path (as in I use that path for commands such as node /usr/local/bin/forever
Or have I got my wires crossed? Am I even supposed to be able to run a node module/package without specifying the full path? Is there any reason why it's not good practice to do so?
Many thanks.
I am so silly - editing the .bashrc file did seem to work. (Actually I'm not sure if this did work, or if it was automatically set correctly the whole time)
What I didn't realise is that I needed to:
Restart the terminal
Run a global package with just it's name (no "node" prefix)
EG in ubuntu cmd line:
node forever -h // WRONG!
forever -h // Works!
Thought I'd post in case someone in a similar situation finds this.
I've been trying to install npm globally in virtual box with ubuntu 14.04 and Apache 2.4 with various problems with Laravel 5.1
Reading through the docs on npm adn following through these instructions https://docs.npmjs.com/getting-started/fixing-npm-permissions I know I have completed wrecked my $PATH
Previously when I ran echo $PATH I got something like this;
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games
Now when I echo $PATH I get the following;
/usr/local/bin:/bin
I have managed to stuff everything up on my Laravel install, composer no longer works, php artisan no longer works - am just wondering if anyone is able to help me get back to where I was...
For the novices who may be struggling with this, I got the path, composer, artisan and Laravel functioning by first, replacing the .bashrc with a non corrupt one in terminal from the /etc/skel directory (in local indicated by $)
$cp /etc/skel/.bashrc ~/
Commit changes with
$source ~/.bashrc
Then used the following to export /usr/bin to my PATH - the error for anything attempted in terminal was "The command could not be located because '/usr/bin' is not included in the PATH"
$export PATH="/usr/bin:$PATH"
To permanently commit the changes
$sudo nano /etc/environment
Check the file contains the following
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
CTRL & X to save and Y
Trying to install node.js.
Did brew install node
It seems to have worked.
However, received this message upon its completion
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
/usr/local/share/npm/bin
Ok ... so, I open my bash_profile...
And this is what I have in it:
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Trying to understand how to modify it correctly so I won't ruin it ...
Do I add /usr/local/share/npm/bin like this
export PATH="/usr/local/bin:/usr/local/sbin:~/bin/usr/local/share/npm/bin:$PATH"
If not, what is the correct way to add that path?
Thank you for any help provided!
PS. let me know if there is any additional information I could have provided
EDIT
upon seeing which npm in macedigital's answer, I ran that ...
and got this: /usr/local/bin/npm
and that was before I did the second answer (ie, ThiefMaster's answer).
ran which npm again ...
and got the same answer as before ...
i did echo $PATH and got this:
/Users/name/.rvm/gems/ruby-1.9.3-p374/bin:/Users/name/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/name/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/name/.rvm/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin
So, it looks like I already had it installed?
Therefore, how do I handle the answers? I hate leaving it unresolved since both of you were so helpful and I feel bad that I asked without providing echo $PATH information since that would have told you that I had it installed ...
EDIT 2
ls -la /usr/local/share/npm/bin gets this:
ls: /usr/local/share/npm/bin: No such file or directory
which -a npm gets this: /usr/local/bin/npm
EDIT 3
ls -a /usr/local/bin/npm gets this: /usr/local/bin/npm
there's no timestamp...
Short answer, do this (notice the additional colon I inserted):
export PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
The $PATH environment variable is colon separated list of directories to look in if you want to run a command without a fully qualified path (e.g. running npm instead of having to type /usr/local/share/npm/bin/npm).
You can try this from a terminal before actually saving the change in bash_profile. If everything is good, which -a npm will show you all fully qualified path(s).
UPDATE
It is not necessary to modify the $PATH variable in order to use npm. What homebrew install recommends instead is to add the directory where npm-installed binaries are stored to the $PATH variables, so its more convenient to use them from the command line later on.
Node modules like phantomjs, phonegap, express, etc. provide binaries which after the change are available on the command prompt without having to type the full path.
The cleanest solution is adding the following between the two lines you posted:
export PATH="/usr/local/share/npm/bin:$PATH"
That way everything stays readable and you prepend it to PATH just like the program suggested it. And if you ever want to undo the change you just remove that line instead of editing a possibly long line.
In PATH ORDER IS IMPORTANT. So anything before desired npm version will still cause problems.
#adding in first place of the path, before anything else
export PATH=/usr/local/bin:otherPathEntries:$PATH
assuming that version of npm You want is in /usr/local/bin, to check all use 'which -a npm'
I'm on OS X.8 and a newbie at Node & LESS. I thought I installed lessc earlier and when I go to /usr/local/bin I see lessc
but for the life of me, I can't run it. Anytime I do run it, I see
-bash: lessc: command not found
So I've tried the tip here which has the following:
ln -s ~/.npm/less/1.3.3/package/bin/lessc my/local/dir
My local dir happens to be on a second drive on my laptop, here's the path:
/Volumes/Mac17/Users/denis2/Sites/staging/assets/less
With all that said, I try and run:
lessc boostrap.less
and still get
-bash: lessc: command not found
I'm totally lost here and any help would be tremendous.
Just follow the steps :
Make lessc executable by your user(permission denied means you dont have permission to run) like chmod 755 lessc
Export the location of lessc into the PATH like export PATH=$PATH:/home/user/folder/path/less/bin (where lessc is present)
Use lessc lessc boostrap.less
You should put PATH export in environment so that you dont have to do it every time you login See here :
Setting environment variables in OS X?
If you enter just lessc, it is searched in the $PATH. For security reasons, the current directory is not in the $PATH. Try
./lessc bootstrap.less
or, if that doesn't work, simply
~/.npm/less/1.3.3/package/bin/lessc bootstrap.less
If you get a Permission Denied error then, you may need to mark the file as executable. Use
chmod a+x ~/.npm/less/1.3.3/package/bin/lessc
to do that. You may also need to call node directly, if it isn't in your $PATH.