Make sure that /usr/local/bin is in your $path.

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

echo $PATH

You should see something like this

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

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/node

Why, 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/npm 

Select 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/bin

That 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
done

And 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
done

Question

When I do 'open .profile' in the terminal I have the following:

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

Now 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/bin

In 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:$PATH

To make the edited value of path persists in the next sessions

cd ~/
touch .bash_profile
open .bash_profile

That 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/mypath2

In MAC OS Catalina, this are the steps that worked for me, all the above solutions did help but didn't solve my problem.

  1. check node --version, still the old one in use.
  2. cd ~/
  3. atom .bash_profile
  4. Remove the $PATH pointing to old node version, in my case it was /usr/local/bin/node/@node8
  5. Add & save this to $PATH instead "export PATH=$PATH:/usr/local/git/bin:/usr/local/bin"
  6. Close all applications using node (terminal, simulator, browser expo etc)
  7. restart terminal and check node --version

How do I add usr local bin in my path Mac?

Method #1: $HOME/.bash_profile file to set or change $PATH under macOS.
Open the Terminal app on macOS..
The syntax is as follows using the export command to add to the PATH on macOS: ... .
In this example, add the /usr/local/sbin/modemZapp/ directory to $PATH variable. ... .
Append the following export command:.

Where is usr local bin on macOS?

How to access /usr/local/bin in the Finder.
From the menu bar, select Go ➙ Computer (Shift + ⌘ + C).
Click Macintosh HD..
Select usr ➙ local ➙ bin or any other file path you need..

How do I find my path on Mac?

Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.

What is $PATH in Mac?

To find the PATH variable on Mac, open a terminal window and run echo $PATH. After which, the shell will return a list of all the directories currently listed under the PATH environment variable on your Mac.