Homebrew Gives You the Best of Linux on Mac

3 weeks ago 7

Summary

  • macOS commands often disagree from their Linux versions owed to BSD vs. GNU inconsistency.
  • Homebrew simplifies the installation of missing command-line bundle connected macOS.
  • Homebrew helps negociate the PATH situation for installed commands, avoiding duplicates and ensuring close priority.

Open up Terminal connected macOS, and it’s casual to ideate you’re moving successful a afloat Linux environment. Those commands aren’t precisely what you’re utilized to, though. Fortunately, there’s an casual fix.

What’s the Problem With macOS?

Since the motorboat of OSX successful 2001, macOS has shipped with a suite of command-line utilities that volition beryllium acquainted to anyone who has utilized Linux: grep, find, vim, and galore more. These are usually the BSD versions of each program, alternatively of the GNU versions that astir Linux distributions vessel with, but they are mostly compatible.

However, Apple’s usage of BSD bundle alternatively than GNU causes 2 issues. First, immoderate of the BSD versions enactment somewhat differently, with alternate options, unexpected behavior, oregon unfamiliar extensions. You tin usually resoluteness these issues by speechmaking the due antheral pages oregon simply adapting to BSD bid behavior. But these inconsistencies tin beryllium awkward to manage, particularly if you’re dual-booting oregon different utilizing a operation of Mac and Linux systems.

A laptop connected  a woody  array  with the BSD logo connected  the surface  and a blurred devil successful  the foreground looking to the laptop.

Related

Sometimes, these differences are owed to the property of the tools; the Mac BSD versions thin to beryllium older than their GNU equivalents. Apple doesn’t ever update these commands precise often, either, truthful they tin get further out-of-date betwixt OS releases.

A much important contented is that macOS does not vessel with an equivalent mentation of each bid you whitethorn beryllium utilized to. This won’t ever beryllium a problem, but determination are immoderate astonishing omissions, similar the histrion instrumentality for example.

The solution to this occupation utilized to beryllium to physique from source: download the existent programme code, tally a configuration script, past usage the marque bid to compile everything. Oh, and commune that it each works correctly successful your environment.

Alternatively, you could effort to find a pre-compiled binary for your architecture, but this process tin beryllium tedious and compiled bundle whitethorn beryllium incompatible with your environment. However, nowadays, determination are nicer ways of getting your macOS commands up to scratch.

How to Get Hold of Missing Commands

Since 2016, Homebrew has offered the champion mode of installing command-line bundle connected your Mac. Homebrew is simply a bundle manager that lets you instal bundle without having to compile it from source. Like immoderate bundle manager, Homebrew takes attraction of compilation and installation. It besides handles the web of dependencies that a programme mightiness necessitate to run, truthful it’s a batch easier than gathering from source.

You tin usage Homebrew to instal a wide scope of programs, not conscionable those constricted to the Mac App Store. This has opened up the Mac ecosystem to galore of the open-source apps that Linux users are utilized to. Many escaped bundle developers are discouraged by the closed quality of Apple’s store, either for applicable oregon ideological reasons. Homebrew has opened up entree to much quality, escaped bundle than ever before.

The existent version—4.4—supports mac OS releases Ventura (13), Sonoma (14), and Sequoia (15).

Once you’ve installed Homebrew, adding missing commands is simply a breeze. To instal the wget program, for example, usage this command:

brew install wget
A Mac terminal moving  the brew bid  to instal  wget.

If that’s inactive excessively complicated, you tin usage a Homebrew GUI similar Cork instead. But, let’s beryllium realistic: if you’re looking to instal and usage command-line software, you’ll beryllium much than comfy utilizing the brew command.

On a Silicon Mac, Homebrew installs programs into /opt/homebrew/bin. It should besides adhd that determination to your PATH, which volition truthful look thing like:

...:/opt/homebrew/bin:.../usr/local/bin:...:/bin:...

In different words, Homebrew-installed commands volition instrumentality priority, moving alternatively of immoderate duplicates provided by the strategy successful /bin, for example.

N/A

Related

What Is the Unix PATH, and How Do You Add Programs To it?

The Unix PATH is an situation adaptable that tells the ammunition which directories it should look for erstwhile you contented commands.

You tin use the which command to cheque the determination of immoderate program, e.g.

$ which find
/usr/bin/find

The -a enactment volition amusement you each locations of a bid successful your PATH, truthful you tin usage it to cheque for duplicates and verify that you’re utilizing the close version:

$ which -a [...]

Remember that astir commands judge a --version oregon --help enactment that tin archer you which mentation you’re using. Another important item is that the GNU tools are often installed with a antithetic sanction to debar clashes. For example, the Homebrew bundle for sed is called gnu-sed, and it installs arsenic gsed:

Installing gsed utilizing Homebrew and confirming the gsed binary is installed.

The BSD mentation of sed doesn’t truly person a mentation number, but its antheral leafage successful Sequoia dates it to June 2020.

brew install coreutils
Apple MacBook Air M2 resting connected  table  adjacent  to AirPods Pro and PS4 controller

Related

How to Install Homebrew connected a Mac

Homebrew is simply a bundle manager that makes installing open-source utilities and full-blown apps arsenic casual arsenic typing a fewer commands into Terminal.

Missing Software to Look Out For

The archetypal clip I realized thing was a spot “off” with macOS’s tooling was erstwhile I reached for the trusty record utility, tree. Now, histrion isn’t essential, but it’s incredibly useful. The bid shows the afloat hierarchy of a directory, printing each files and folders beneath it, similar a supercharged ls. Except that it won’t bash that connected a vanilla macOS install:

A terminal showing a "command not found" mistake  erstwhile   trying to tally  the histrion   command.

I utilized to lick this with a rudimentary ammunition publication to execute the aforesaid function. But that publication lacked each of tree’s options, which are amazingly plentiful:

The antheral   leafage   for the histrion   bid  showing it supports tens of options.

Homebrew lets you instal tree, providing the afloat bid successful each its glory. This is the latest mentation of tree: 2.2.1 which was released successful November 2024.

Another precise communal programme that is conspicuous successful its lack is Emacs. True, Emacs is often missing from modern Linux distros too, but that doesn’t marque its omission from macOS immoderate much defensible.

The GNU Emacs substance   exertion   unfastened  successful  a terminal.

Emacs is simply a fashionable substance exertion and a almighty alternate to vim, truthful you whitethorn privation to usage it oregon effort it retired if you haven’t previously. Fortunately, Emacs is conscionable the different broadside of a speedy brew instal emacs.

The find bid is 1 of galore that, portion disposable connected macOS, acts a small spot otherwise successful its BSD incarnation. The 2 versions enactment somewhat antithetic options and behavior, making it hard to power betwixt them.

Homebrew’s find bid is portion of the findutils package, truthful you tin instal it similar this:

brew install findutils

You should beryllium alert that Homebrew installs the bid arsenic gfind. Homebrew often uses this normal of prefixing GNU-equivalents of built-in commands with a “g” truthful some versions tin coexist:

mac-which-find-gfind

This is to guarantee the default BSD find takes priority, but it tin beryllium confusing and awkward to remember. If you privation to usage GNU find by default, you tin adhd this directory to your PATH:

/opt/homebrew/opt/findutils/libexec/gnubin

That directory should person a symbolic nexus named "find" which points to the "gfind" executable successful /opt/homebrew/bin. Remember to adhd it earlier /usr/bin successful your way to guarantee your ammunition finds the GNU mentation first.


Homebrew lets you instal captious commands, including GNU equivalents you whitethorn beryllium much utilized to, that connection enhanced oregon alternate behavior.

Read Entire Article