The best kittens, technology, and video games blog in the world.

Friday, May 28, 2021

How to configure OSX 11.4 Big Sur for software development

wilma kitten-4 by julochka from flickr (CC-NC)

With every new Macbook, I'm updating the guide, previous version is here.

Basics

  • Go to Settings > Security > FireVault, turn on FireVault. This will restart your computer.
  • Install some sensible browser like Chrome or Firefox.
  • Afterwards either sign up into your account on which you hopefully have your ad blocker setup, or install some. Most popular seems to be uBlock Origin these days, but pretty much any of them will do just fine.
  • Install whichever cloud sync service you're using like Dropbox etc. And start syncing your stuff.
  • Install iTerm2 for sensible terminal emulator.
  • Clean up all crap from dock. Other than Launchpad and System Settings, everything else should be gone. Add iTerm2, your browser, and your text editor, and any application you wish to install there instead of stock Apple crap.

Editor

Install some sensible text editor. These days most people use Visual Studio Code. If you do, go to Options, search "Telemetry" and disable it all.

If that's your choice, run it, open Command Palette, and choose: "Shell Command: Install 'code' command in PATH".

Settings

Like every other operating system, OSX has a lot of bad default settings. Here are some obvious fixes:
    • If you have multiple monitor setup, go to Settings > Display > Arrangement and drag and drop them into correct arrangement so mouse can move between them correctly.
    • You might need to do it twice - with laptop screen open, and with laptop screen closed.
    • Also set up which will be your main monitor by dragging that white bar on top of the display icon to it. This looks like Menu placement, but it really mostly controls Dock placement.
    • Settings > General > Appearance > Dark
    • Settings > Mouse > Untick "Scroll direction: Natural" to get rid of stupid backward scrolling
    • Settings > Mouse > increase scrolling speed and tracking speed a bit
    • Settings > Keyboard > Key Repeat > Fast (max is correct)
    • Settings > Keyboard > Delay Until Repeat > Short (max is correct)
    • Settings > Sound > Disable "Play sound on startup"
    • Settings > Sound > Disable "Play user interface sound effects"
    • Settings > Sound > Alert volume > 0% (for Terminal ping)
    • Settings > Trackpad > Scroll & Zoom > Disable "Scroll direction: natural" (this should be done if you do it for mouse)
    • Settings > Displays > Max out brightness
    • Settings > Displays > Turn off "Automatically adjust brightness"
    • Settings > Dock & Menu bar > enable "Automatically hide and show the Dock"
    • Settings > Dock & Menu bar > Battery > Enable "Show Percentage"
    • Settings > Dock & Menu bar > Clock > Use a 24 hour clock
    • iTerm > Preferences... > Profiles > Terminal > Unlimited Scrollback
    • Settings > Desktop & Screen Saver > Screen Saver > Disable
    • Settings > Security & Privacy > Require password after sleep > 1 minute
    Press Ctrl-Up arrow, add a few desktops (or "spaces" as they were used to know), then go to Settings > Keyboard > Shortcuts > Mission Control - and enable their keyboard shortcuts Ctrl-1 to Ctrl-6 or however many you have there.

    Open Screenshot app, choose options, then:
    • disable "Show Floating Thumbnail"
    • Save to > Other Location... choose "Downloads" folder

    Drivers

    OSX already includes drivers for laptop itself, but you might need some for peripheral hardware.

    In particular, external PC keyboard need a tweak to work properly, as left and left Windows keys are in reverse order from Mac keyboard.

    Go to Settings, Keyboard, Modifier Keys..., choose the right keyboard from the dropdown (strangely I had ordinary wireless mouse selected by default), and swap positions of Option and Command keys. Feel free to change functionality of Caps Lock key as well, it's a huge easily accessible key with no useful function people love to remap, usually to extra Control.

    If you need any special keyboard layouts, get them too.

    Another thing - when you plug in external keyboard, you'll get choose keyboard type dialog. It will likely choose the wrong type. Just pick ANSI, whatever it claims to detect. Otherwise the backtick key will be wrong.

    Home/End keys on OSX are also broken. Use this as a fix. You'll need to log out and log back in for it to take effect.

    Development tools

    You'll need a package manager, and the only one anyone uses is homebrew, MacPorts and the rest being basically dead. You need to tell homebrew to not spy on you with brew analytics off command.

    You'll need Xcode. Fortunately homebrew installer does it for you automatically. If you don't use homebrew for some reason, you can install Xcode manually by running xcode-select --install from command line.

    Deal with stupid access popups

    New in Big Sur, first time you access some folders from terminal, you get a stupid popup asking you to confirm that you're indeed fine with terminal accessing various folders. So run:

      find .

    and confirm all those stupid popups to be done with it once and for all. Well, except you'll still have them when accessing USB drives and such. I'm not sure if there's any way to completely disable this nonsense.

    Create new SSH key pair

    Before you do that, name your computer something memorable with sudo scutil --set HostName your_host_name command.

    Open Terminal and run ssh-keygen to create ~/.ssh/id_rsa, then upload the generated key to any place that needs to know about it like githubbitbucket, or whatever else you use.

    Alternatively you could copy your keys from your old laptop, but it's generally more secure to have separate fresh keys for each machine.

    Checkout your dotfiles

    Hopefully you're storing your dotfiles somewhere. If it's a git repository, or your Dropbox account, get them now and symlink them all properly.

    If there are any other repositories you might need, checkout them too.

    Standard paths

    OSX renames a lot of directories. The most annoying of those is that instead of /home it has /Users. It used to be very easy to add a symlink, but this kept getting more and more complicated, so I stopped doing this.

    Install homebrew packages

    Your list might vary. Here's a few obvious suggestions:

    brew install rbenv ruby-build mc wget p7zip trash git htop bash zsh youtube-dl jq imagemagick coreutils bash-completion zsh-completion nodeenv

    Then enable all services you installed, unless you want to start them manually:

      ln -sfv /usr/local/opt/*/*.plist ~/Library/LaunchAgents/

    And install non-system ruby, so you can install gems without sudo. Currently latest is:

      rbenv install 3.0.1
      rbenv global 3.0.1

    To make that actually work, you need to make sure ~/.rbenv/shims is in your $PATH. If you type rbenv init, it will tell you what to do.

    Due to OSX limitations you'll need to run sudo htop if you want to use htop.

    Install gems

    Again, your list my vary. These days most of the software will have its own Gemfile so long list of gems are generally unnecessary. But some global utilities are still useful:

    gem install bundler rak pry pry-rescue

    Different Shell

    OSX switched from ridiculously outdated bash to up to date zsh, so it's no longer a mandatory step

    If you want to use system zsh, it's fine.

    If you want to install something else, like proper bash (or brew version of zsh; or something else), first brew install bash.

    You'll need to edit /etc/shells as admin and add the following lines at the end of it to enable your newly installed shell:
    /usr/local/bin/bash
    /usr/local/bin/zsh

    Then set it as your shell, with whichever one you prefer:
      chsh -s /usr/local/bin/bash $USER
      chsh -s /usr/local/bin/zsh $USER

    Hushlogin

    For some reason OSX prints worthless annoying messages on every open terminal tab. Run to touch ~/.hushlogin to prevent that.

    Coreutils

    This is optional step. OSX coreutils are generally a lot worse than GNU versions you might be used to from Linux. Switching unfortunately means occasional minor incompatibilities, but I never ran into anything serious.

    If you want to do so, brew install coreutils, then add GNU coreutils to your PATH:

      export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
      export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

    OSX coreutils are not as bad as they used to (for example cp -a now work), so this step can be skipped.

    Better window manager controls

    Sadly OSX window manager is extremely dubious for keyboard use. Fortunately programs to make it usable exist. Unfortunately there's a lot of churn among those programs, and every couple of years the ones I use become unmaintained and need to be replaced by something else.

    Currently I recommend:
    • Rectangle - for moving windows around on big screens - I don't really like the default keybindings, so I change them to Cmd-Control-Option with 1,2,3,4 for corners, arrows for halves, and M for maximize and get rid of the rest
    • AltTabfor switching between windows - it's baffling that OSX completely lacks this function - and Cmd-Tab to switch between applications is absolutely inadequate for any application that has more than one window, which is most of them (browsers, editors, terminals etc.) if you're developing software. My previous recommendation HyperSwitch no longer works.
    Due to Apple's increasing levels of hostility towards Open Source software, you'll now need to open Security & Privacy > General, and then allow HyperSwitch to run.

    You'll need to give them necessary access. To do so:
    • Settings > Security & Privacy > Privacy > Allow the apps below to control your computer > enable HyperSwitch and Rectangle
    Also open its preferences, and set it to run in the background, show in menu bar, and start at login.

    Open files limit

    For some insane reason OSX has default open file limit of only 256, and that breaks a lot of software like databases. And every new OSX version breaks 

    You will need to fix this (current instructions), restart computer, and put ulimit -n 100000 in your .zshrc for good measure.

    Lower security settings

    Unix used to have very simple model where root user could do anything, and that was great for development. OSX keeps adding more and more security restrictions. They are absolutely detrimental to developing software, and of questionable value to regular users - primarily they're Apple's way of slowly turning computer world into something more like iOS world where they can decide who can run what and take 30% tax on everything.

    You'll need to disable some of them. Most important such setting is this:
    sudo spctl --master-disable
    After you run it and reboot, a lot of software like Ghidra will work properly.

    Enable ssh access

    You need to tick both:
    • Settings > Sharing > Remote Login > Turn on
    • Settings > Sharing > Remote Login > Allow full disk access for remote users

    Android File Transfer

    It's honestly embarrassing to both OSX and Android that there's no out-of-the-box way to move files between them either over WiFi or USB cable.

    There's official Android File Transfer program but it's just awful. OpenMTP is somewhat less awful, but still not great. If you know of any program that's actually good, definitely let me know.

    All other software

    There's a lot of other software you might want. The most obvious one is the VLC media player.

    You might also want some kind of Git UI program, like GitUp (brew install homebrew/cask/gitup).

    If you want to use SSHFS, the one in homebrew (macfuse and sshfs packages) don't seem to work, so you might want to try downloadable versions. First time you try to use it, OSX will block it, so you'll need to go to Settings > Security & Privacy, allow it there, and restart (you'll get popup for that).

    Enjoy

    Once you go through this list, and successfully get everything going, I'd recommend modifying it to your liking and reposting your version on your blog. Everybody's needs are different, so guide like this is just a starting point.