MrBrady
MrBrady

Reputation: 21

How do I set Node path (Homebrew) for Sublime Text Prettier plugin configuration so it survives Node updates?

I have Node installed via Homebrew. The path is /opt/homebrew/Cellar/node/21.1.0.

I've installed the Prettier Sublime Text plugin (JSPrettier) which requires the Node path to be defined. Defining it as /opt/homebrew/Cellar/node/21.1.0 gets it working.

However, whenever I update Node, the path changes.

How do I set this up so the Prettier Sublime Text plugin configuration and survive Node updates?

Manually updating the path works, but it's not very efficient.

Upvotes: 0

Views: 359

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207818

When you install a package using homebrew, it puts a versioned copy in its "Cellar" and creates an unversioned link to it in its bin directory. That way, you just add the bin directory to your PATH and your shell can always find the latest versions of every package you have installed - so you should generally avoid using specifically versioned executables.

The locations of "Cellar" and bin directory differ according to the CPU architecture on a Mac:

  • on Apple Silicon, homebrew uses /opt/homebrew/Cellar and /opt/homebrew/bin
  • on Intel Macs, homebrew uses /usr/local/Cellar and /usr/local/bin

You can tell which one of the two locations it is using by running:

brew --prefix     # prints "/opt/homebrew" on Apple Silicon and "/usr/local" on Intel

So, if you get a long listing of /opt/homebrew/bin for the htop package on Apple Silicon, you can see:

ls -l /opt/homebrew/bin

lrwxr-xr-x  1 mark  admin    29 Jul  9 15:35 htop -> ../Cellar/htop/3.2.2/bin/htop

which means there is an unversioned, plain htop in /opt/homebrew/bin/htop which just points to the latest v3.2.2 htop in the "Cellar".

TL;DR

Use the unversioned links in /usr/local/bin or opt/homebrew/bin unless you really, really need a specific version of anything.


Note that if you are programmer/developer, the story is slightly more complicated. You will use "include files" (a.k.a. "header files") and libraries (e.g. libxyz.so) and pkgconfig files (i.e. with .pc extension). These are linked in exactly the same way as executables, so you use:

gcc/clang -I /opt/homebrew/include -L /opt/homebrew/lib  # Apple Silicon

or

gcc/clang -I /usr/local/include -L /usr/local/lib        # Intel Macs

or, if you want your compilation/linking to work on either architecture:

gcc/clang -I "$(brew --prefix)/include" -L "$(brew --prefix)/lib" ... 

Upvotes: 1

Related Questions