/
Setup Homebrew While Using Unprivileged Account

Setup Homebrew While Using Unprivileged Account

Introduction

Homebrew won’t install properly if you use a regular account. You must use an account that has sudo privileges. But if you follow best practices, your normal user account is not able to use sudo.

Setup Everything

Installing

The Trick - Use “s - Use “sudo” Enabled Account

Not really a trick, but for non unix users it feels like one.

Make sure to go into an account that allows privileged access to sudo. In this case for me it's not my normal restricted user tin.pham account, but setup.admin,

su - setup.admin

And follow the install instructions at Homebrew.

After install, make sure to add the brew path to your main account AND your everyday user accounts. Note these instructions were from my Mac OS X Mojave 10.14.6 terminal after completing my install. These instructions might change depending on your Mac OS version, so don’t just copy mine,

==> Next steps: - Run these commands in your terminal to add Homebrew to your PATH: echo >> /Users/setup.admin/.bash_profile echo 'eval "$(/usr/local/bin/brew shellenv)"' >> /Users/setup.admin/.bash_profile eval "$(/usr/local/bin/brew shellenv)" - Run brew help to get started - Further documentation: https://docs.brew.sh

So from my terminal still as setup.admin but I prefer to use ~ which is a variable for my current user's home directory

echo >> ~/.bash_profile echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.bash_profile eval "$(/usr/local/bin/brew shellenv)"

Older Mac Version and Xcode

Homebrew depends on the Command Line Tools for Xcode and installs it for you. However, for older Mac OS it is not smart enough to install the most up to date version. This will cause issues when you install packages. Scrolling up to my Brew installation, notice that it downloaded Xcode 10.3,

==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress ==> Installing Command Line Tools (macOS Mojave version 10.14) for Xcode-10.3 ==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ Mojave\ version\ 10.14)\ for\ Xcode-10.3 Software Update Tool Downloading Command Line Tools (macOS Mojave version 10.14) for Xcode Downloaded Command Line Tools (macOS Mojave version 10.14) for Xcode Installing Command Line Tools (macOS Mojave version 10.14) for Xcode Done with Command Line Tools (macOS Mojave version 10.14) for Xcode

In my case for an older Mac OS I pulled from the Apple Developers site.

Check what version you I have,

# confirm where it is working from pkgutil --pkg-info=com.apple.pkg.CLTools_Executables package-id: com.apple.pkg.CLTools_Executables version: 10.3.0.0.1.1562985497 volume: / location: / install-time: 1740537066 groups: com.apple.FindSystemFiles.pkg-group

So you must remove this old version manually otherwise you’ll have issues,

# confirm the diectory xcode is at curently xcode-select -p /Library/Developer/CommandLineTools # it's the right directory so, sudo rm -rf /Library/Developer/CommandLineTools

As I currently have 10.0.1, downloaded 11.3.1 (the last supported version) and installed as follows,

  1. Locate the .dmg file: Open Finder and navigate to the location where you downloaded Command_Line_Tools_for_Xcode_11.3.1.dmg.

  2. Open the .dmg file: Double-click on the .dmg file to mount it. This will create a virtual disk on your desktop or in the Finder sidebar.

  3. Run the installer: Inside the mounted disk, you should see an installer package (usually named something like Command_Line_Tools.pkg). Double-click on this package to start the installation process.

  4. Follow the prompts: The installer will guide you through the installation process. Follow the on-screen instructions to complete the installation.

# confirm new version pkgutil --pkg-info=com.apple.pkg.CLTools_Executables package-id: com.apple.pkg.CLTools_Executables version: 11.3.1.0.1.1576735732 volume: / location: / install-time: 1740543048 groups: com.apple.FindSystemFiles.pkg-group

Confirm Brew Works

Test to make sure things work by running brew update,

brew update ==> Updating Homebrew... Already up-to-date.

Install your favourite utility. Note as it’s installing from source it can take a long time,

# confirm untility does not already exist wget -bash: wget: command not found # install utility brew install wget # it stayed at this line for a long time ==> Installing wget dependency: gettext ==> ./configure --with-libunistring-prefix=/usr/local/opt/libunistring --disable-silent-rules --with-included-gli # but then eventually finished

Then exit into your normal user account and replace the username accordingly and in my case it’s tin.pham

exit # if you are unsure of your user use whoami whoami tin.pham # now I add brew to my path, again ~ which is a variable for my current user's home directory echo >> /Users/tin.pham/.bash_profile echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.bash_profile eval "$(/usr/local/bin/brew shellenv)"

Confirm wget is found in your path. Using this command you should see the brew path as shown,

which wget /usr/local/bin/wget

Installing Brew Apps

You must sudo into your sudo capable account first. See my list of must install tools for the Mac,

su - setup.admin brew install md5

Cleaning Up

Clear up files and failed installs,

su - setup.admin brew cleanup

Updating Brew

You must sudo into your sudo capable account first.

Error Updating Brew Between Mac OS X Updates

Updating Homebrew may result in error if you do it in between Mac OS X updates,

brew update Error: The /usr/local directory is not writable. Even if this directory was writable when you installed Homebrew, other software may change permissions on this directory. For example, upgrading to OS X El Capitan has been known to do this. Some versions of the "InstantOn" component of Airfoil or running Cocktail cleanup/optimizations are known to do this as well. # Reset the ownership and permissions of /usr/local back to your user account, sudo chown -R setup.admin:admin /usr/local/

In this in case using the chown is no longer possible with Mac OS X "High Sierra" 10.13.4 and you will receive the following error,

sudo chown -R setup.admin:admin /usr/local/ chown: /usr/local: Operation not permitted

Instead just uninstall,

...

Ignore the note about the folders to delete. I my example remotdesktop was generated by another program. No idea why Homebrew would  tell you to delete folder other program's create.

Related content