How to make the most current version of git available on macOS

macOS and Xcode are always a few releases behind the currently available version of git. There are just a few simple things you need to do in order to rectify this inequity. If you are reading this then you are probably already familiar with the git CLI commands, but just to be sure:

  • check the version of git
ewilson$ git version
git version 2.9.3 (Apple Git-75)
  • check to see where git is being executed from
ewilson$ which git
/usr/bin/git

If your system looks like this then you'll need to modify your .bash_profile (if you run bash - or modify the profile file for your corresponding shell). Since I am going to use homebrew for the new git install I need to make sure the path of the new executable (brew installs in /usr/local/bin) comes before the macOS version which is typically located in /usr/bin. Thusly:

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

Now all that's left is to install git and you are golden

ewilson$ brew install git
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
metricbeat
==> Updated Formulae
...

==> Downloading https://homebrew.bintray.com/bottles/git-2.10.2.sierra.bottle.1.tar.
######################################################################## 100.0%
==> Pouring git-2.10.2.sierra.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d

zsh completion has been installed to:
/usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/git
==> Summary
🍺/usr/local/Cellar/git/2.10.2: 1,445 files, 31.8M

Now when you run git version you should see the latest and greatest

ewilson$ git version
git version 2.10.2

Awesome. To keep things up to date all you'll need to do is run brew upgrade

brew upgrade git

Don't forget to update any tools or IDEs that you may have been using to make sure that they now point at your shiny new version of git.

How to fix golang "unrecognized import path"

Recently when trying to run go get I ran into the the following error:

ewilson$ go get github.com/nu7hatch/gouuid
package crypto/md5: unrecognized import path "crypto/md5" (import path does not begin with hostname)

After some trial and error (and a few conflicting opinions) I chose to unset my $GOROOT environment variable. Apparently when you compile go (I use brew for most installations) the correct $GOROOT value becomes embedded in the go tool. When you set it manually you can end up conflicting with the correct setting.

You may actually need to run the unset command as once a variable is set it may only be unset by using the unset command.

ewilson$ unset GOROOT

Onward.

How to repair Homebrew after OS X upgrade

I was getting the following error when running brew after the latest upgrade to OS X (El Capitan).

 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

I couldn't even run brew update - arg.

This is what I did to correct the issue - git to the rescue!

cd /usr/local/Library

git pull origin master

git pull will throw an error if you have changes in the directory (/usr/local/Library). If so, you'll have to fetch the master branch and perform a hard reset.

git fetch --all

git reset --hard origin/master

You should be able to now use brew again - hurrah!

Note: in the event you installed Homebrew as a non-root user, you'll need to cd to /Users/non-root-user-rname/homebrew/Library instead of /usr/local/Library.

How to unpack a .deb file on Mac OS X without installing it

If you use Xcode, a utility called ar is installed. You can run the following command:

ar -x path/to/filename.deb

If you don't use Xcode, you could also install ar using Homebrew and run the same command.

Alternatively, you could use Homebrew to install the dpkg utility which has many more options to work against .deb files.

dpkg -c path/to/filename.deb

Homebrew update fail

I was looking to upgrade my Scala installation and thought I'd update Homebrew before doing so. I got the following error message when performing the update:

mac-attack:~ ewilson$ sudo brew update
Checking out files: 100% (3246/3246), done.
warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renamelimit variable to at least 1019 and retry the command.
Error: undefined method `to_sym' for nil:NilClass
Please report this bug:
    https://github.com/mxcl/homebrew/wiki/troubleshooting
/usr/local/Library/Homebrew/cmd/update.rb:97:in `report'
/usr/local/Library/Homebrew/cmd/update.rb:95:in `each_line'
/usr/local/Library/Homebrew/cmd/update.rb:95:in `report'
/usr/local/Library/Homebrew/cmd/update.rb:18:in `update'
/usr/local/bin/brew:94:in `send'
/usr/local/bin/brew:94

Obviously not what I was expecting as brew is usually pretty reliable. After doing some FAQ reading I came across this command:

mac-attack:~ ewilson$ sudo brew doctor

The command provided me with some recommendations of configs, paths and symlinks that needed to be corrected. I followed the guidance and my issues were solved.