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

Monday, January 16, 2023

How to configure OSX 13.1 Ventura 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.

Things didn't change too much from the previous version. The main difference is that because new Macbooks use Apple Silicon and that causes endless issues, it's pretty much mandatory to install Docker.

Basics

  • Go to Settings > Privacy & Security > FileVault, turn on FileVault. Do not use iCloud for recovery, just note your recovery key somewhere. This used to require computer restart, but it just works now.
  • 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 iTerm2 for sensible terminal emulator. If you start it, it will also prompt you to install XCode Command Line Tools, which you'll definitely need, so do it now.
  • Install whichever cloud sync service you're using like Dropbox etc. And start syncing your stuff.
  • 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. To make Spaces work correctly, you'll also need to set your external monitor to be the main one by drag and dropping menu bar to it.
    • 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 > Appearance > Dark. If you're setting up a new laptop, this will be asked during installation.
    • Settings > Keyboard > Key Repeat > Fast (max is correct)
    • Settings > Keyboard > Delay Until Repeat > Short (max is correct)
    • Settings > Keyboard > Disable keyboard brightness completely. Defaults (slow keyboard, highlight keys) are meant for people who are bad at typing. If this somehow applies to you, get some typing lessons, you can save huge amount of time by getting better at typing.
    • Settings > Keyboard > Text Input > Edit ... > Disable "Add full stop with double-space" - this one really messes up coding
    • Settings > Trackpad > Scroll & Zoom > Disable "Natural scrolling". This will also apply to the mouse, restoring correct direction.
    • Settings > Sound > Disable "Play sound on startup"
    • Settings > Sound > Disable "Play user interface sound effects"
    • Settings > Sound > Alert volume > 0% (for Terminal ping)
    • Settings > Desktop & Dock > enable "Automatically hide and show the Dock"
    • Settings > Desktop & Dock > disable "Automatically rearrange Spaces based on most recent use"
    • Settings > Displays > Max out brightness
    • Settings > Displays > Turn off "Automatically adjust brightness"
    • Settings > Displays > Turn off "True Tone"
    • Settings > Control Center > Battery > Enable "Show Percentage"
    • Settings > Control Center > Clock > Clock Options > Use a 24-hour clock. This might be already on based on your regional choices during installation.
    • Settings > Mouse > increase scrolling speed and tracking speed a bit
    • Settings > Lock Screen > Start Screen Saver when inactive > Never. You should generally be doing it yourself, and you often need to leave the laptop running upgrades or unit tests or such, and you want to be able to see the status without constantly poking it.
    • Settings > Lock Screen > Require password after screen saver begins or display is turned off > After 5 minutes. You can move it down to 1 minute if you use your laptop in public. I don't recommend Immediately, as that causes endless annoyance with connecting and disconnecting external monitors and just moving laptop around requiring new password.
    • Settings > Sharing > Remote Login > Turn on
    • Settings > Sharing > Remote Login > (i icon) > All Users
    • Settings > Sharing > Remote Login > (i icon) > Allow full disk access for remote users
    • iTerm > Preferences... > Profiles > Terminal > Unlimited Scrollback
    Press Ctrl-Up arrow, add a few desktops (or "spaces" as they were used to know), then go to Settings > Keyboard > Keyboard Shortcuts > Mission Control - and enable their keyboard shortcuts Ctrl-1 to Ctrl-6 or however many you have there. Sometimes I've seen shortcuts for extra desktops not being there, and in such case I just restarted, and the problem fixed itself.

    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.

    New Macbooks now come with Fn/Globe key. You probably don't need i to change your keyboard layout so feel free to use it for emoji keyboard or something like that.

    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 died long time ago. You need to tell homebrew to not spy on you with brew analytics off command.

    You'll need Xcode. Fortunately iTerm does it for you automatically, and if not homebrew will. If you need to do it manually 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. 

    And just to be extra sure, go to Settings > Privacy & Security > Full Disk Access, and add iTerm there.

    Create new SSH key pair

    Before you do that, name your computer something memorable with sudo scutil --set HostName your_host_name command. You probably go through a lot of laptops, so names like "Name's Macbook" are completely useless to you. Just pick a theme like cats or dinosaurs or whatnot, and give every computer a distinct nam

    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.1.3
      rbenv global 3.1.3

    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.

    There's also asdf that offers this kind of service for all languages, if you want to use it instead of rubenv/nodenv/etc. I don't recommend rvm, I've seen it cause too many issues in the past.

    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. However switching means occasional minor incompatibilities, so it's up to you if you want to do it or not.

    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 works), 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. Also set Repeated commands to "cycle through displays".
    • 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.
    You'll need to give them necessary access. To do so:
    • Settings > Security & Privacy > Privacy > Allow the apps below to control your computer > enable AltTab 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.

    You can do it for processes in terminal by putting ulimit -n 100000 in your .zshrc, which might be adequate, but not every process runs from the terminal. 

    Enabling it globally gets more and more complicated with every OSX version. Instructions for Ventura are here.

    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.

    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.

    On Linux and Windows it's possible to mount MTP devices, which is very slow, but still beats OpenMTP. I don't know if it's possible on OSX.

    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 > Privacy & Security, allow it there, and restart (you'll get popup for that).

    Docker

    There's a lot of software that just plain won't run on Apple Silicon, so you'll need Docker. You can either use Docker Desktop, or if you have licensing issues with that Rancher Desktop. If you use Rancher, set it to Docker compatibility mode.

    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.