The best answers to the question “Making sure /usr/local/bin is in my $PATH on mac” in the category Dev. QUESTION: I’ve installed node.js for Macintosh using the lastest installer for Macintosh. I now want to check that /usr/local/bin is in my $PATH, as the installer instructed. I’ve opened up the Terminal application and
researched help on the net, but I’m lost, as to how to accomplish the above, then start the node.js process. Can anyone clear this up? Thank you for very much. ANSWER: open terminal and type the command below You should see something like this the presence of /usr/local/bin in the output means you are good to go ANSWER: echo $PATH will print your path. If you see /usr/local/bin between some colons, then it’s in
your path.
I installed node and made sure that /usr/local/bin is in my $PATH.
I checked for node install version and location
[~]$node -v v10.15.1 [~]$which node /usr/local/bin/nodeWhy, when I cd into /usr/local/bin/, is there nothing there?
I'm on MacOS Mojave Version 10.14.2. I installed node version 10.15.1 using the installer downloaded from nodejs.org, and using the default options in the installer.
Here are the notes i took from the installer:
Welcome to the Node JS Installer -> This package will install: • Node.js v10.15.1 to /usr/local/bin/node • npm v6.4.1 to /usr/local/bin/npmSelect the disk where you want to install nodejs -> MacintoshHD
(clicked install) ...
This package has installed: • Node.js v10.15.1 to /usr/local/bin/node • npm v6.4.1 to /usr/local/bin/npm Make sure that /usr/local/bin is in your $PATH.Checked /usr/local/bin is in $PATH.
[~]$echo $PATH :~/usr:bin:~/bin:usr/local/bin:usr/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:But the when I check where node is installed:
[~]$which node /usr/local/bin/node [~]$cd usr/local/bin/node -bash: cd: usr/local/bin/node: No such file or directory
macosnode.js
I've installed node.js for Macintosh using the lastest installer for Macintosh. I now want to check that /usr/local/bin is in my $PATH, as the installer instructed. I've opened up the Terminal application and researched help on the net, but I'm lost, as to how to accomplish the above, then start the node.js process. Can anyone clear this up? Thank you for very much.
Best Solution
echo $PATH will print your path. If you see /usr/local/bin between some colons, then it's in your path.
The PATH variable holds a list of directories separated by colons, so if you want to add more than one directory, just put a colon between them:
export PATH=$PATH:/usr/local/git/bin:/usr/local/binThat syntax works in any Bourne-compatible shell (sh, ksh, bash, zsh...). But zsh, which is the default shell in recent versions of MacOS, also exposes the PATH another way - as a variable named (lowercase) $path, which is an array instead of a single string. So you can do this instead:
path+=(/usr/local/git/bin /usr/local/bin)In either case, you may want to check to make sure the directory isn't already in the PATH before adding it. Here's what that looks like using the generic syntax:
for dir in /usr/local/git/bin /usr/local/bin; do case "$PATH" in $dir:*|*:$dir:*|*:$dir) :;; # already there, do nothing *) PATH=$PATH:$dir # otherwise add it esac doneAnd here's a zsh-specific version:
for dir in /usr/local/git/bin /usr/local/bin; do if (( ${path[(i)$dir]} > $#path )); then path+=($dir) fi doneQuestion
When I do 'open .profile' in the terminal I have the following:
export PATH=$PATH:/usr/local/git/binNow I installed node.js for Mac and it says,
Make sure that /usr/local/bin is in your $PATH.
How can I add /usr/local/bin to export PATH=$PATH:/usr/local/git/bin?
Solution
This works in either bash (which is the default shell pre-Catalina) or zsh (which is the default shell from Catalina onward):
export PATH=$PATH:/usr/local/git/bin:/usr/local/binIn zsh you can also do this for the same result:
path+=(/usr/local/git/bin /usr/local/bin)OTHER TIPS
Try placing $PATH at the end.
export PATH=/usr/local/git/bin:/usr/local/bin:$PATHTo make the edited value of path persists in the next sessions
cd ~/ touch .bash_profile open .bash_profileThat will open the .bash_profile in editor, write inside the following after adding what you want to the path separating each value by column.
export PATH=$PATH:/usr/local/git/bin:/usr/local/bin:Save, exit, restart your terminal and enjoy
I've had the same problem with you.
cd to ../etc/ then use ls to make sure your "paths" file is in , vim paths, add "/usr/local/bin" at the end of the file.
I tend to find this neat
sudo mkdir -p /etc/paths.d # was optional in my case echo /usr/local/git/bin | sudo tee /etc/paths.d/mypath2In MAC OS Catalina, this are the steps that worked for me, all the above solutions did help but didn't solve my problem.
- check node --version, still the old one in use.
- cd ~/
- atom .bash_profile
- Remove the $PATH pointing to old node version, in my case it was /usr/local/bin/node/@node8
- Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"
- Close all applications using node (terminal, simulator, browser expo etc)
- restart terminal and check node --version