Install Git On Macbook Pro

Last updated on 30 December 2019.

Intro

I have to set up a MacBook Pro fairly often - when starting a new job and when buying a new personal computer. I created this article back in 2015 when I got my first Mac and have been updating it ever since with whatever I need as my job evolves. As you run through the install process, you will need to be an administrator of your system to install this package, as it will ask you to input the password for your account. Once the process is complete, open a new Terminal window and type “git”, you should see the following output if the software is installed correctly. Installing Git for a Mac - Duration: 3:57. Knight Center Courses 10,419 views. How to Install and Configure Git and GitHub on Windows - Duration: 21:18. I have two Macs, a ten-year-old Mac Pro desktop computer, and a five-year old MacBook Pro laptop. Both are fine for writing code. Buy a used Macintosh. When you get a coding job your employer will give you a new computer. Most beginners buy a new 13' MacBook Air, Apple’s cheapest model. You’re better off buying a used MacBook Pro.

This article describes how to install Ubuntu Linux on your MacBookPro.

Hardware

Apple MacBook Pro 'Core i7 2.9 15' Touch/Mid-2017 with AMD Radeon Pro 560

Target OS/Distro

Linux <=4.15, >=4.20 or >=5.0 on Ubuntu 18.04/19.04

Not working but can be worked around

- Audio input & output

I am using a USB Wi-Fi adapter TP-LINK TL-WN722N for $15 and for audio any bluetooth headphones/speakers is working fine.

Update: It appears that setting ccode and regrev to 0 in the firmware partially fixes the WiFi, seehttps://bugzilla.kernel.org/show_bug.cgi?id=193121#c25 (See Update 6 below!)

Update 2: As many have been asking, here is a ready ISO with Ubuntu 18.04 for MacBook (Linux 5.0.0-15), touchbar and keyboard are working.

(See Update 7 below - I've added new links there.)

Update 3 If you are experiencing a 'black screen on boot' issue with the Linux kernels v4.18, v4.19 then try booting with amdgpu.dc=0 kernel argument.

Update 4 The 'black screen' issue was related to this commit https://github.com/torvalds/linux/commit/e03fd3f300f6184c1264186a4c815e93bf658abb
Having it reverted has solved the issue. https://github.com/Dunedan/mbp-2016-linux/issues/73#issuecomment-422397681

Update 5 I've updated the ISO with the latest Ubuntu version, SW, drivers.
Article has been updated to target Ubuntu 18.04.2 with the Linux kernel 5.0.0-15.

Update 6 Finally, there is a way of having your MBP's Broadcom wifi adapter working! All that needs to be done is placing the right brcmfmac43602-pcie.txt file into a /lib/firmware/brcm/ directory. Then, reloading the brcmfmac driver. You can find the brcmfmac43602-pcie.txt file here https://bugzilla.kernel.org/show_bug.cgi?id=193121#c52 Make sure you set the macaddr in the brcmfmac43602-pcie.txt file to the same value that brcmfmac43602-pcie.bin has inside or you can see it using this command ip address show dev wlp3s0

Update 7 (30 Dec 2019) I've updated the ISO with the latest Ubuntu version, SW, drivers.
Article has been updated to target Ubuntu 18.04.3 with the Linux kernel 5.3.0-24 (the kernel is coming from the future Ubuntu Focal 20.04 LTS distro).

I added MacBookPro15,4 line to the /etc/udev/hwdb.d/61-evdev-local.hwdb file of this image as an attempt to see whether the touchpad will start working in new MacBookPro 2019 https://github.com/cb22/macbook12-spi-driver/issues/77

The /lib/firmware/brcm/brcmfmac43602-pcie.txt file from https://bugzilla.kernel.org/show_bug.cgi?id=193121#c52 was added to the image so that WiFi will be working out of a box.

Download 2.8G: https://files.nixaid.com/ubuntu4mac.iso
SHA256:
a77086a4aadbfd5b29e86232a9e24aba
0f3a963af064e3c961adae8e9f8d2682

Preparing the disk

Partition for your Linux installation

You would need 10 GB minimum or 25 GB recommended space for the Ubuntu 18.04 installation.

All you need to do is to reduce your Macintosh HD partition from macOS by using Disk Utility. The freed space will be used by the Ubuntu Linux installer.

Remastering Ubuntu distro

I used another laptop running Ubuntu to apply the steps described in this section.

There are two drivers which you need to add to your Linux in order to avoid the unnecessary hassle with connecting external USB keyboard/mouse/stick as most of the howto's suggest.

By creating your own remastered Ubuntu Linux distribution, you will have a handy recovery tool you can use at any time.

Get Ubuntu

You can download it from its official website https://www.ubuntu.com/download/desktop

Extract the image

You need to extract the Ubuntu image before you can start remastering it.

Chroot to the image

Once the image is extracted, you will need to continue remastering it from inside. To do so, you will need to use chroot.

Update the image

It is a good idea to keep the software updated.

HWE

Since MacBookPro mid-2017 is a pretty new hardware, it makes sense to ensure you are running it on the newest Linux kernel (except for v4.18,v4.19 due to a 'black screen' bug) and the display server (Xorg).

In Ubuntu you can use the LTS Enablement Stack which is achieved simply by running the following command:

I've excluded the linux-generic-hwe-18.04 since it brings v4.18 kernel with the 'black screen' bug.

Use Linux kernel 5.3 from Ubuntu Focal release

Since there is a black screen issue
with the Linux kernels between v4.18-rc1 and v4.20-rc4.
We will install newer Linux v5.3 from Ubuntu Focal 20.04 LTS.

For this, we will use APT Pinning.

Install Linux 5.3 from Focal release

Cleanup old kernels

DKMS: Keyboard, touchpad and touchbar

To avoid hassle with plugging the external keyboard/mouse, you can already build in the keyboard, touchpad and touchbar drivers.

Note though, that Linux kernels higher than 4.15 have their touchbar driver refactored,
you can find upgrading notes here

For the Linux kernels before 4.16, please use this legacy driver branch

Before kernel 4.16

Do not follow this if you are using Linux kernel higher than 4.16.

If you want the F-keys to be always on by default and the Fn button for switching from F-keys to special keys, then use the following command:

After Linux kernel 4.15

Do not follow this if you are using Linux kernel lower than 4.16.

If you want the F-keys to be always on by default and the Fn button for switching from F-keys to special keys, then use the following command:

Common

This section is common to wheher you are using legacy monolithic driver or not.

You can also swap fn and a control keys:

Or remap it to any other key:

Touchpad configuration

Next, you need to set the proper dpi for the touchpad:

DKMS: USB WiFi TP-LINK TL-WN722N

FROM UPDATE 6: You can skip this section! There is a way to get your MBP's wifi adapter working (see Update 6 in the beginning of this article)

TP-Link TL-WN722N v2 support has been added to the Linux kernel starting v4.13-rc2 https://github.com/torvalds/linux/commit/5a1d4c5dd4eb2f1f8a9b30e61762f3b3b564df70
So you can skip this section entirely if you happened to be using a recent kernel.

In order to enable the external TP-LINK TL-WN722N USB WiFi adapter, you need to make sure the Ubuntu image has the necessary driver.

Exit chroot environment

Exit the chroot environment when you are done modifying the Ubuntu image.

Update the kernel

To ensure the remastered Ubuntu boots the latest Linux kernel which you have installed in the chrooted system.

Build remastered Ubuntu image

The following steps are to build the remastered Ubuntu image.
When running xorriso, keep in mind the order of arguments is important.

Test the new image

Make sure your remastered image boots, before writing the it to your USB stick.

Out of the following methods, you would likely only need UEFI -> USB.

Install the UEFI firmware and qemu for running virtual machines:

Legacy (BIOS)

CDROM: qemu-system-x86_64 -enable-kvm -m 1G -k en-us -cdrom ubuntu4mac.iso
USB: qemu-system-x86_64 -enable-kvm -m 1G -k en-us -device nec-usb-xhci,id=xhci -drive if=none,id=stick,file=ubuntu4mac.iso,format=raw -device usb-storage,bus=xhci.0,drive=stick

UEFI

CDROM: qemu-system-x86_64 -enable-kvm -m 1G -k en-us -bios /usr/share/ovmf/OVMF.fd -cdrom ubuntu4mac.iso
USB: qemu-system-x86_64 -enable-kvm -m 1G -k en-us -bios /usr/share/ovmf/OVMF.fd -device nec-usb-xhci,id=xhci -drive if=none,id=stick,file=ubuntu4mac.iso,format=raw -device usb-storage,bus=xhci.0,drive=stick

Installing the Linux

Boot your MacBookPro from your newly remastered Ubuntu - ubuntu4mac.iso
and create the following partitions:

/dev/nvme0n1p4 EFI 1024 MB
/dev/nvme0n1p5 /boot ext4 1024 MB
/dev/nvme0n1p6 physical volume for encryption (all free space)
on top of /dev/mapper/nvme0n1p6_crypt set ext4 and / as a mountpoint

Make sure you have set /dev/nvme0n1p5 as a 'Device for boot loader installation'.

Include your DKMS modules

Repeat the steps from the DKMS: Keyboard, touchpad and touchbar and DKMS: USB WiFi TP-LINK TL-WN722N sections, but only in the /target mountpoint, so you will have to be chrooted. To chroot into the /target, see the commands below under Chrooting to your system section.

Get the Ubuntu EFI files back to their place

When the Ubuntu Linux installation finishes, do not restart your MacBookPro yet.

The Ubuntu installer mounted /dev/nvme0n1p1 instead of /dev/nvme0n1p4 as an EFI partition and put Ubuntu EFI files in there.
To fix this, apply the following steps.

Move Ubuntu EFI files to a correct partition

Tell the future system to use a proper EFI partition

Get UUID of your EFI partition by running blkid /dev/nvme0n1p4 and set it in the /target/etc/fstab file for the /boot/efi mountpoint.

Set proper EFI boot record

Without this record your MacBookPro will not boot into the installed Ubuntu Linux.

Boot your Linux

Now you can reboot your system without the remastered Ubuntu image.
In order to boot back into macOS, just hold 'option' button while your laptop is booting and select 'Macintosh HD'.

Recovery

Having the remastered Ubuntu Linux USB stick handy, you can boot off it, mount your partitions where Ubuntu is installed, chroot into it and fix the issues.

Mounting your system

Chrooting to your system

Install Git On Macbook Pro

Now you can fix things like EFI boot records, changing Linux kernel, updating drivers and so on.

Exitting chroot

Unmounting your system

Extra hints

Swap command and option keys

Once you have logged-in under your user in the Gnome/Unity session, run the following command to permanently swap command and option keys:

Windows in QEMU/KVM

You can download Windows 10 for free and install/use it in QEMU/KVM.
https://www.microsoft.com/software-download/windows10

Steam in Docker

As a great surprise for some, you can play games in Linux on your MacBookPro using AMD Radeon Pro 560.
For that you can either install Steam on your own or use my Steam image which is much simpler https://hub.docker.com/r/andrey01/steam/

Grub to show options

This is important as one day you may get a Linux kernel that won't boot due to some problem. To prevent this, make sure you are able to choose the kernel when your MBP starts.
To do this, remove the GRUB_HIDDEN_TIMEOUT* lines from the /etc/default/grub file and make sure GRUB_TIMEOUT is set to some reasonable value, e.g. 5 (without quotes).
Then regenerate grub config by running sudo grub-mkconfig -o /boot/grub/grub.cfg command.
This will allow you to see the grub loader options on boot and let you pick a different kernel in case if the last one was having troubles to boot/or any other troubles.

Grub to show macOS High Sierra option

Add the following code to /etc/grub.d/40_custom file:

Install Git On Macbook Pro

Then regenerate grub config by running sudo grub-mkconfig -o /boot/grub/grub.cfg command.

After that you do not need to hold the 'option' button to load macOS when restarting your MBP.

When upgrading a Linux kernel

Make sure your kernel drivers have been compiled each time you are getting a Linux kernel upgrade. For that, run dkms status command and see whether the module has installed status there.

Troubleshooting

macOS got update and GRUB is not booting anymore

One day you may find yourself in a situation when only macOS is booting, while GRUB boot loader is being completely skipped.

Do not worry, you can set your Linux boot option back from macOS itself.

You can do this by using the bootoption tool

  1. Install Xcode from the App Store.
  2. Install bootoption:
  1. List your UEFI boot preferences:

You can also see more info for each option:

  1. Set ubuntu to be 1st in your boot order:

If you get this error, do not worry, this is due to the SIP (System Integrity Protection). All you need is just to disable it (you can enable it later):

After that the commands will work as expected:

You can also use sudo bootoption set --bootnext 0000 command for one-time boot.

References

- Linux On MBP Late 2016
- MBP 2016 Linux

I am trying to install Subversion and GIT on my mac because I want to use it with limejs. I believe I’ve installed it correctly but I keep getting this error in the terminal: -bash: svn: command not found
this happens with both SVN and GIT, is there something I’m missing or that I’m doing wrong?

Observing members: 0 Composing members: 0

11 Answers

It could be that they aren’t in your unix path. See this article for adding something to your unix path.

I believe you were right, I added that line of code to my terminal and now it gave me this : >

do I need to write something else after that?

How To Install Git On Macbook Pro

Thanks!

@gorillapaws I believe you were right, I added that line of code to my terminal and now it gave me this : >
do I need to write something else after that?
Thanks!

@polycinco how are you installing them? homebrew? macports?

An aside: I’ve been thinking about playing around with html5/canvas stuff. What makes limejs more compelling than any of the other frameworks out there?

Set your path to Unix only then they will install.

@phaedryx I wasn’t using either of those or anything else, I enrolled in a course to make HTML5 games which requires Limejs GIT and subversion. I couldn’t tell you what the difference is between Limejs and others because I’m new to all of these and that’s why it’s being kind of hard to even install those things /:

@abundantlife I believe I did that but would you mind guiding me through it?

@polycinco I personally like homebrew because it makes it really easy to install things (e.g. it automatically downloads and installs programs and creates symlinks so that they’ll be in your path).

You can read about it on their website, but the commands are pretty simple. Open up “Terminal” (you’ll need to type/copy the things I’ve bolded to the prompt).

1. Install homebrew:
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)

2. install subversion:
brew install subversion

3. install git:
brew install git

4. switch to your home directory:
cd

5. check out the limejs repository:
git clone git://github.com/digitalfruit/limejs.git

6. switch to the limejs directory you just made:
cd limejs

7. initialize:
bin/lime.py init

8. Create a new project:
bin/lime.py create helloworld

9. Open up ~/limejs/helloworld/helloworld.html in your browser and take a look

@phaedryx Thank you so much! This is really helpful. I started with number 1 and got this on Terminal: Last login: Tue Sep 11 10:07:49 on ttys000
Cinthyas-MacBook-Pro:~ polycinco$ ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press enter to continue
> Downloading and Installing Homebrew…
/dev/fd/63:132:in `chdir’: Permission denied – /usr/local (Errno::EACCES)
from /dev/fd/63:132
Cinthyas-MacBook-Pro:~ polycinco$

Why does it say permission denied?

Thanks again!

I means that the user ‘polycinco’ on your system doesn’t have permissions to the ’/usr/local’ directory. You can see what the permissions are by typing:
ls -al /usr/ grep local
(it will give you the permissions string, a number, the name of the user who owns the directory, the name of the group who owns the directory, and some other info)

On my system I added my user to the ‘admin’ group, for you it would be:
sudo dseditgroup -o edit -a polycinco -t user admin

(it will probably prompt you for a password)

and make ’/usr/local’ group-writeable:
sudo chmod g+w /usr/local

and try going through my previous steps again.
————————————————————————————————-
If that doesn’t work for you, you can try installing it as the superuser:
sudo ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
————————————————————————————————-
Or if all else fails, open permissions to /usr/local to everything before installing:
sudo chmod 777 /usr/local

but make sure to change it back when you’re done:
sudo chmod 755 /usr/local

@phaedryx Thank you so much! I will try this and let you know what happens, hopefully this will fix it!

Answer this question

This question is in the General Section. Responses must be helpful and on-topic.