macOS - first experiences from a Linux user perspective


(Link to this article on twitter: https://twitter.com/sxaTech/status/1628064140576059392)

A while back I took delivery of a Mac Mini M1 system ("2020" model with 16Gb RAM running MacOS 11.6 "Big Sur" (It's now on 12.3). It came with no keyboard, mouse or screen (but I had plenty of them around, including a Unicomp Model M buckling spring keyboard with mac keycaps which I'd acquired a few months previously!) First problem was that the HDMI output didn't seem to want to talk to the 1600x1200 screen I had on my desk, so I switched it over to my 27" 1080p display ...

So what's it like to use? I've used macOS systems as servers before but other than a small amount of GUI remote access I hadn't seriously used a desktop system before so I wanted to share "first timer" experience for some common use cases as a developer. Oh, and it's quick. Really quick. Whatever Apple have done in designing the M1 ("Apple Silicon") CPUs which are Arm64 they've done an amazing job and left very little room for criticism. It is a big.LITTLE setup with four high performance cores and four energy efficient ones and, somewhat surprising to me, also implements seems to natively implement the (optional) 32-bit Arm instructions - useful if you want to run Linux containers for that architecture.

Start with a terminal (obviously!)

The most important thing particularly if you're coming from Linux is to find a terminal window! You need to go to Finder -> Utilities -> Terminal. Finder is the Blue/White face on the left of the dock bar:

From there the Terminal icon can be clicked to start or (recommended) dragged into the "dock" at the bottom of the screen so it's always there when you want it. If you want to launch another one, you need to left click to start a new terminal window, or you can use CMD+T to open a new tab in the existing window. To switch between tabs in the terminal, use CTL+Tab and CTL-Shift_TAB rather than CTL-PgUp/PgDn as it often is elsewhere. Note that the first time you access some of the new folders withing the terminal shell you'll get a popup dialog saying that "Terminal" would like to access files in your <directory> folder. Your terminal does not have access to everything under your user ID by default.

Navigating the keyboard and window management

While if you're new to macOS it seems strange not to have menu bars on each window but instead they are all in a bar at the top of the screen that adjustsitself based on the application you're currently using. I'd used it on remote systems enough that it didn't bother me but it's the most ovious difference in the macOS UI compared to others. The other thing to remember if you're coming from another machine is that while Mac keyboards do have a "Ctrl" key it's generally not used and most of the operations which you'd use Ctrl for on another system are done with one of these two keys instead

  • Command (or Cmd) ⌘
  • Option (or Alt) ⌥

You can snap windows to the left or right but to do it you have to hover the mouse over the green icon in the top left of an active window and it'll drop down a menu with options to send the window full screen, zoom, left or right:

If you're using a UK keyboard, the keystroke for the # character is Option+3. The Euro symbol € can be found at Option+2 if you need it.

Finding your way around the system

The Apple logo is always leftmost in the menu bar at the top of the screen and gets you to the sleep/restart/shutdown/lock/logout options as well as the apple "App Store" for installing apps and also "System Preferences" which has most of the system options. The "Activity Monitor" and system "Console" (which shows you crash dump info) are not in the System preferences - for those you need to navigate to the "Utilities" directory with the Finder app - they're in the same place you used to launch the terminal window. 

In System Preferences you can enable remote ssh connections. To do this, go to "Sharing" in the System preferences and check the "Remote Login" checkbox. On the top of the sharing page you can also set the hostname to something better if desired. "Screen sharing" in the same panel will also allow you to connect over VNC if you so desire (You can use "open vnc://<ip address>" from another mac to connect or try another client)

There is no auto-focus functionality but this third-party tool apparently allows it, and if you set it up appropriately it can auto-focus but not raise to the front on focus if that's what you want. 

Keyboard shortcuts

As mentioned earlier, many of the keys are the same as on other systems but use the Cmd" button rather than "Control" e.g. Cmd+X/C/V is cut/copy/paste. Command+Space brings up the Character viewer for inserting emojis etc. and Shift+Cmd+5 brings up screen capture/recorder. Command+comma brings up the current app's preferences. A full list of shortcuts is at https://support.apple.com/en-us/HT201236

Try not to hit the Ctrl key twice as that will attempt to initiate dictation (Not much use without a microphone)

There is no default keystroke for maximizing a window but I set mine to CTRL+Cmd+Up via System Preferences -> Keyboard -> Shortcuts -> App Shortcuts and setting a new one for a menu title of "Zoom" Ref: https://apple.stackexchange.com/questions/372719/maximize-window-shortcut#372732

A few essentials to download for serious work

I wanted the consistent experience of using Firefox as my primary browser so I grabbed that from https://www.mozilla.org. Note that videoconferencing tools did not work well for me under FireFox using an external USB camera - the sound is quite garbled/robotic apparently like the sound in Beastie Boys 'Intergalactic' according to my colleague Beth - but it's ok in Safari so I've had to stick with that. I also needed virtualisation software. VirtualBox (many people's favourite) isn't available, and VMware Fusion and Parallels cost money, so one remaining option which is based on qemu is UTM from https://mac.getutm.app. This gives you a fairly basic GUI over the top of QEMU, and unlike the other solutions it lets you start up VMs of different architectures as well as the native aarch64.

Also while I'm trying to do everything natively, if you try to run a macOS application which has not been converted to aarch64 macos will prompt you to install Rosetta2 which is their dynamic translation layer for x86-64 macOS apps which is provided for backwards compatibility. Alternatively you can explicitly install it with:

  • softwareupdate --install-rosetta

But bear in mind that installing Rosetta 2 is a one way thing - you can't easily uninstall it afterwards (This may work though). If you want to use it, but keep a separate environment for testing without Rosetta, you might wish to consider running macos on macos using the Virtualization framework. If all else fails, you can always factory reset the mac. (TL;DR for reference because I've done it a few times: Shut down, Switch on but hold power button, Options -> Continue -> Log in -> "Reinstall macOS"


One further quick note on Rosetta - while it will generally just "do the right thing" some applications are provided as "universal" binaries which have x64 and ARM versions inside them (You can check by running "file" against them). If you want to force something to run under Rosetta from the command line, prefix it with "arch -x86_64".

And now for the other UNIX OSS tools - brew

Many other pieces of UNIX software can be installed using the brew utility. You can download this from the brew.sh website. brew acts like a package manager, and installs software into "/opt/homebrew" on aarch64, or /usr/local on x64 (You can also install brew on Linux, in which case it uses /home/linuxbrew/.linuxbrew) If you are willing to risk running shell scripts from the internet, then use this command to install brew onto your host:

  • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Containers with Docker (or podman)

Docker is available from https://docs.docker.com/desktop/mac/apple-silicon but bear in mind that unlike on Linux, containers are capped by default (4CPU, 2Gb as far as I can tell) which could be too restrictive for some memory intensive operations (Rosetta2 is optional, but installing it will allow you to run x64 images using docker --platform linux/amd64. Note that the docker for desktop licensing has changed as of 2022, so you may wish to use podman machine instead which can be installed via brew, or you can download podman desktop (although I haven't tried that myself ... yet).
  • brew install podman
  • podman machine init --cpus 7 --memory 8192 --now
--now tells it to execute `docker machine start` afterwards. Pick the number of CPU cores and amount of RAM you wish to be made available to your containers. Next, use the machine init command to set up a virtual Fedora CoreOS image to run the containers in, although you can connect into that intermediate machine with "docker machine ssh" if you need to (You probably won't though). Note that if you want to use volume mounts you have to have podman 4.0.2 or later and define the volume in the intermediate VM with `-v` on the `podman init` command e.g.
  • podman machine init --cpus 7 --memory 8192 -v $HOME/map:/map
  • docker run -it -v /map:/map ubuntu bash
As mentioned before the M1 CPUs are quick, and this translates very will into the performance of Linux containers there too - I had a build of OpenJDK17 in a Linux/aarch64 container on the M1 complete in three minutes. If you want a quick Linux/aarch64 desktop system, this is probably the best there is. So if you're one of those people (like me... see picture below) who has lots of little Arm single board computers (SBCs) for playing with Linux on Arm, you may find this quote from a colleague applies: "The trouble with these boards is that you don't need to get many until you should have just plumped for a Mac Mini and gotten something with real performance that actually works..."

Compiler tools - Xcode or the cut down command line tools?

The other thing you'll probably want is a compiler. Apple's development environment is called Xcode and includes the compilers for various languages including C/C++. The "command line tools" are easy to install and if you've installed brew it will have pulled them down automatically when it installed brew. Otherwise run xcode-select -install or if you just try and run gcc the GUI will prompt you to install it. The command line tools will give you most of what you need for building C/C++ applications. You can install other versions including the "full" Xcode (and you'll need that if you need the "metal" tool (Required for building OpenJDK17+). Make sure the version you install is suitable for your MacOS version. Xcode 13.3 will not work on macOS11 for example. You can either install the latest from the app store or find different versions from https://developer.apple.com/download/all/q=xcode (which can also be used to install Xcode in a virtualization framework VM - see later for why that's an issue) The normal location if it us under /Applications but it will run from anywhere (Note, extracting from the direct donwload rather than the app store bypasses the verification step and it will instead occur when you first use it. You'll also have to run xcodebuild -license accept) and then use sudo xcode-select -s to set the default xcode to the Xcode-app directory in the location that you extracted into (To get back to the default install of the command-line tools, use sudo xcode-select -p /Library/Developer/CommandLineTools or often just sudo xcode-select -s / - you can check the current value with xcode-select -p)

File Types

If you've downloaded Xcode from the Apple developer site it will have come down as an .xip file. Some of the other formats you might see applications supplied as, and how to extract them, are listed below:
  • .pkg - Application installer. Double click or "sudo installer -pkg package.pkg -target /"
  • .dmg - Compressed disk image format - double click then comy when prompted or mount with `sudo hdiutil attach file.dmg` - find it under `/Volumes` then copy the contents of the `.app` directory to `/Applications`.
  • .xip - file that can be extracted with `xip -x` - Note that if you do this in an empty directory you'll have to use `cd $PWD` to see the extracted data (!)

macOS on macOS with the Virtualization Framework

Apple has introduced the Virtualization Framework on macOS (See this video from WWDC2022) which is an API that lets you create and use virtual machines on a Mac. It's very much a "no frills" system, but there is some sample code to use it which will fire up a virtual machine with a GUI on your mac's screen and it works quite well. The same code comes with a tool that downloads a macos virtual image so other than the amount of time it takes to download. At the time of writing it pulled down a 14Gb "ipsw" restore archive with macOS 12.6. An ipsw - apprently "IPhone SoftWare" file is a zip containing everything needed for your device, including dmg (virtual disk) files and other things.

Virtualizing macos on macOS is useful for a few reasons. Firstly (and probably the most common use case) is to allow you to try new versions of macOS without risking switching your machine over to it.  Secondly the other use case - that is of more interest to me - is that it allows you to have a machine that you can clear up and reset to test things on a clean machine.

To get started with Virtual Machines using the Virtualization Framework, download the sample code and make sure you have full Xcode installed (If I find a way to do it without full xcode or the GUI I'll update this post ...). You can then open the project inside the zip and and open the "xcodeproj" file in the directory. There are versions of the tool using Swift or Objective C and both function exactly the same. I've been using the Objective-C one. 


There may be a better way to do this, but on the Xcode interface there is the panel above - the bit shown on the right which says "InstallationTool-Objective-C" is clickable and will let you switch between that and the sample app, in both swift and Obj-C versions. Start with the installation tool then press the triangle "Play" button. That should start the download of the image to $HOME/vm.bundle. Once that is complete you can use the drop down to switch to the "macOSVirtualMachineSampleApp-Objective-C" and start that with the Play button and hopefully it will fire up a window and start your new clean virtual machine. The virtual "Disk.img" it extracts from the .ipsw archive is about 68Gb in size and has holes in it so if you want to back it up at any point use tar to it can be restored in the same way. Depending on your use case you may wish to enable remote VNC access and ssh as described earlier (IP will likely be 192.168.64.something - the command below will probably show you it) and the same sharing panel can be used to enable file sharing from the host over SMB - it'll show up in the Finder.

VMIP=`arp -a | grep 192.168.64 | grep -v 192.168.0.255 | tail -1 | awk '{print$2}' | tr -d '()'`

The first time you do this you may also have a failure relating to signing - if so click the top level of the project in the left navigation in the Xcode UI, click the problematic application under "TARGETS" then go to the "Signing & Capabilities" tab where you will be able to select a "Team". Similarly if you get a problem with it saying that the macos version is incompatible, use the "macOS Deployment Target" section of Build Settings to make sure it matches your host system.

The only problem with the virtual machine that I have experienced is that you cannot access the mac App Store with it - it will reject your credentials when you log in (and since you'll probably try a few times before realising what the problem is it will eventually try and force a password reset on you!) It's unclear why this happens, but it is reported on the Apple Developer forums:

There are suggestions from other communities that it requires your connectivity to be on an interface named en0, although since my host mac is using en1 (Like the virtual one) that may not be the source of the problem.

Conclusion

The above pretty much covers most of what anyone will need to know when moving from Linux (or possibly something else) to macOS. Hopefully this will help someone have a slightly smoother learning curve, and make you productive with your mac. If you have any related tips on how to do anything smoother, let me know in the comments!

Comments

Popular posts from this blog

Antisocial Networking: List of Top Tips

Twitter "Likes", labelling people, and BLM