Setting up a Software Development Environment for macOS and Ubuntu Linux


 

INTRODUCTION

I show how to set up a software development environment for macOS and Ubuntu Linux. When we're done, we'll be able to develop programs in C, C++, Python, Javascript, and Lisp using Unix tools.

SYSTEM SETUP - Ubuntu Linux

Ubuntu Linux on a CyberPower PC

This platform is a CyberPowerPC Series C 2019 ET8880-1202 with an AMD motherboard, 1TB SATA disk drive, wireless PCI module, GPU card, Acer monitor, USB keyboard and three button mouse. To install Ubuntu Linux 22.04.1 LTS (Jammy Jellyfish) follow the excellent Ubuntu Desktop Installation instructions.

CyberPower PC CyberPower PC Side View

Here are the steps I used:

  1. Download the Ubuntu distribution for an Intel PC ubuntu-22.04.1-desktop-amd64
  2. Download and install Balena Etcher balenaEtcher-1.19.21.dmg for Mac OS ARM 64-bit. Plug in a 16GB USB Drive into my MacBook Pro. Select the ISO and Drive and copy Ubuntu to USB drive. Balena Etcher Balena Etcher Balena Etcher Balena Etcher Balena Etcher
  3. When booting up, hold down the F2 key and boot into the boot loader screen. Make the USB drive the first option. Boot Options Exit and reboot.
  4. Insert the USB drive and boot. Boot Options
  5. Click on the Install Ubuntu button on the boot screen and the Install Ubuntu on the welcome screen. Install Ubuntu Install Ubuntu
  6. After picking the language, connect to wireless hub. Wireless Wireless Wireless
  7. Do the normal install first. Wireless
  8. We want to clean up the disk paritions, so select Something Else. After that's done, we will continue the install process. Wireless
  9. Generate the main ex4 file system partition and click the Format box, and point mount point at / main drive partiton
  10. Also you need an EFT partition, EFI partition
  11. Also you need a BIOS boot partition, Reserved BIOS Boot Partition
  12. Also you need a swap area partition, Swap area partition
  13. Here is a list of the four partitions, All partitions
  14. If you mess up, Ubuntu will give you warning messages, partition warning
  15. Now go back and we will do an Erase install, Wireless
  16. where are you
  17. User name and password. User name and password
  18. installation continues
  19. install complete
  20. boot sequence
  21. log in screen
  22. When I boot up, it stops in the grub boot. Type exit to continue. exit grub Looks like the first partition for Ubuntu is bad, so I changed the boot order to skip over it and boot from the second Ubuntu partion. change boot order Also look at the solutions in 3 ways to solve booting up in grub prompt
  23. Search for the Software Updater app, launch it, and make it a favorite, so it sticks on the dock. software updater favorite
Terminal

Search for the Terminal app, launch it, and make it a favorite, so it sticks on the dock. User name and password User name and password

Now update the OS,

sudo apt-get update sudo apt-get upgrade sudo apt-get autoremove
Installing Drivers for the GPU
# Check the AMD GPU board is recognized. sudo lshw -c video *-display description: VGA compatible controller product: Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] vendor: Advanced Micro Devices, Inc. [AMD/ATI] physical id: 0 bus info: pci@0000:1f:00.0 logical name: /dev/fb0 version: ef width: 64 bits clock: 33MHz capabilities: pm pciexpress msi vga_controller bus_master cap_list rom fb configuration: depth=32 driver=amdgpu latency=0 resolution=1920,1080 resources: irq:62 memory:e0000000-efffffff memory:f0000000-f01fffff ioport:f000(size=256) memory:fcf00000-fcf3ffff memory:c0000-dffff
Display Drivers

Ubuntu 22.04 LTS has Wayland which replaces X11. To make sure it's enabled, edit this file using sudo nano /etc/gdm3/custom.conf. Change the Wayland line to WaylandEnable=true. Reset using sudo systemctl restart gdm3. Reboot the system. In the lower right corner of the login screen, click on the gear wheel and the default should be set to Ubuntu.

Audio Drivers

If you have a microphone, install an audio driver for it.

sudo apt install gnome-sound-recorder
Firefox Crashes

You may not have this problem. But here is one solution. Install Firefox 64-bit binary for Linux from Mozilla and bypass the Snap version of Firefox entirely. Follow the install instructions Unzip the firefox-128.tar.bz2 and Extract to folder /firefox

# Move the uncompressed Firefox folder to /opt: sudo mv firefox /opt # Create a symlink to the Firefox executable: sudo ln -s /opt/firefox/firefox /usr/local/bin/firefox # Download a copy of the desktop file: sudo wget https://raw.githubusercontent.com/mozilla/sumo-kb/main/install-firefox-linux/firefox.desktop -P /usr/local/share/applications # Launch Firefox. You can add to Favorites in the Ubuntu/Linux Dock. /usr/bin/firefox

Ubuntu Linux Tweaks

We'll make Ubuntu more useful. First read the Ubuntu Desktop Guide.

Clean up Problems with Your Upgrade

If your upgrade didn't go smoothly, you can install and run aptitude.

sudo apt install aptitude sudo aptitude update man aptitude

Run aptitude to diagnose, clean and reinstall your packages.

sudo aptitude update sudo aptitude upgrade sudo aptitude autoclean
Displaying HEIC Images

To show Apple's HEIC formatted images from iPhones as thumbnails in folders and to view them, follow viewing HEIC photos and do this

sudo apt update sudo apt install heif-gdk-pixbuf sudo apt install heif-thumbnailer

Then right click on one of the HEIC images in file folder and select ImageViewer for this file type: HEIC1 HEIC2

Playing MPEG-4 Videos

When you try to open an *.mp4 video on Ubuntu/Linux, it won't open, but you can install software which can play it (or you can just play it in Firefox; all web browsers have MPEG-4 codecs built-in).

mpeg 4 codec
Screen Shots
Use the Space + PrintSysRq buttons to do screen shots
Changing the Terminal Type
I want to execute the bash startup files the same way macOS does. So you need tell Ubuntu to run the terminal window as a login shell:
File Sharing Between Mac and Ubuntu Computers

Install Vim first so you can edit files. Here's how to change the hostname of your system.

# Edit this file and change the name to Gauss cat /etc/hostname Gauss # Edit this file and change the names cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 Gauss ... hostnamectl -h set-hostname --transient Gauss sudo hostnamectl -h set-hostname Gauss sudo hostname Gauss reboot

To install file sharing across computers, find out your username

users seanoconnor

then install Samba, and give a sharing password,

sudo apt-get install samba sudo smbpasswd -a seanoconnor

Let's share the Desktop directory under $HOME. Edit the system config file smb.conf file.

sudo vim /etc/samba/smb.conf ~

Adding these lines to the end,

[share] path = /home/seanoconnor/Desktop valid users = seanoconnor read only = no

Start the Samba client,

sudo apt-get install smbclient sudo service smbd restart

To speed up SMB sharing, (it still takes a minute or two on my Mac), add the IP addresses and hostnames of all your local computers to the /etc/hosts file.

Install ifconfig so you can see the IP addresses.

sudo apt install net-tools

Get the hostname on my Ubuntu Linux computer and its IP address

hostname Gauss ifconfig ... inet 333.333.3.33 netmask 255.255.255.0 broadcast 333.333.3.255 ...

Now go to the macOS computer and get the hostname and IP address,

hostname MacBookProHostName ifconfig ... inet 555.555.5.55 netmask 0xffffff00 broadcast 333.333.3.255 ...

Back in Ubuntu, edit the hosts file by doing sudo vim /etc/hosts. Add these two host names and their IP addresses.

127.0.0.1 localhost ... 333.333.3.33 Gauss 555.555.5.55 MacBookProHostName

On Ubuntu/Linux launch the File Manager application. In your Home directory, right click on the Desktop directory to get Properties. Turn on sharing in Local Network Share and allow others to create and delete files.

Open the firewall for Samba,

sudo ufw allow Samba

Reboot Ubuntu/Linux and log in. Now, back on macOS, mount the shared remote directory, which will prompt you for the Samba password you just set,

cd ~/Desktop mkdir Ubuntu mount -t smbfs //seanoconnor@Gauss/Desktop ~/Desktop/Ubuntu

You'll see the shared directory on the Ubuntu machine, so go ahead and Connect

Backing Up Your System

Format a 2TB USB drive as ExFAT and give it a name.

Then back up your system with rsync. As the article explains the command is

rsync -aAXHv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /media/seanoconnor/Gauss/Snapshot-23-Sep-22-08_51

The -aAX options transfers files in archive mode. This ensures symbolic links, devices, permissions, ownerships, modification times, ACLs, and extended attributes are preserved, assuming that the target file system supports the feature. The option -H preserves hard links, but uses more memory. The --exclude option causes files that match the given patterns to be excluded. The directories /dev, /proc, /sys, /tmp, and /run are included in the above command, but the contents of those directories are excluded. This is because they are populated on boot, but the directories themselves are not created. The command above depends on brace expansion available in both the bash and zsh shells. Quoting the exclude patterns will avoid expansion by the shell, which is necessary, for example, when backing up over SSH. Ending the excluded paths with * ensures that the directories themselves are created if they do not already exist.

Secure Shell Login

I've followed instructions from the article How to Enable SSH on Ubuntu 18.04 to ssh from my Mac to my Ubuntu on my local net. I haven't tried it yet from outside my router but look at Ubuntu's instructions SSH Server Configuration and Servers Behind NAT

Install the ssh server,

sudo apt install openssh-server

Check the status

sudo systemctl status ssh ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-11-29 11:39:54 PST; 33s ago Main PID: 5638 (sshd) Tasks: 1 (limit: 4279) CGroup: /system.slice/ssh.service └─5638 /usr/sbin/sshd -D

Open the firewall

sudo ufw allow ssh Rule added Rule added (v6)

Back on the Mac, ssh into the Ubuntu machine using the IP address. You'll be asked to register an RSA encryption key the first time.

ssh seanoconnor@gauss seanoconnor@gauss's password: Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-46-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 0 updates can be applied immediately. Last login: Fri Aug 26 17:26:27 2022 from 2600:1700:4384:1210:3d5f:29a6:71db:cc27 Entering Python 3.13.0 virtual environment at /home/seanoconnor/.VENV. Type deactivate to exit. seanoconnor:~$ ls Desktop/ Documents/ Downloads/ Music/ Pictures/ snap/ Templates/ Videos/ logout Connection to gauss closed.
Screen Sharing from Mac to Ubuntu

Follow the Ubuntu instructions to enable screen sharing

I allow only local connections. Check the VNC server status:

gsettings set org.gnome.Vino network-interface lo systemctl --user status gnome-remote-desktop.service ● gnome-remote-desktop.service - GNOME Remote Desktop Loaded: loaded (/usr/lib/systemd/user/gnome-remote-desktop.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2022-09-04 20:17:00 PDT; 1h 2min ago Main PID: 4033 (gnome-remote-de) Tasks: 5 (limit: 9334) Memory: 47.3M CPU: 16.623s CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/gnome-remote-desktop.service └─4033 /usr/libexec/gnome-remote-desktop-daemon Sep 04 20:17:00 Gauss systemd[3712]: Starting GNOME Remote Desktop... Sep 04 20:17:00 Gauss systemd[3712]: Started GNOME Remote Desktop. Sep 04 20:17:02 Gauss gnome-remote-de[4033]: RDP server started Sep 04 20:17:02 Gauss gnome-remote-de[4033]: VNC server started Sep 04 21:13:28 Gauss gnome-remote-de[4033]: Refusing new VNC connection: already an active session

In Terminal you'll see the screen sharing server listening on port 5900

ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 0.0.0.0:139 0.0.0.0:* . . . LISTEN 0 10 *:3389 *:* LISTEN 0 5 [::]:5900 [::]:*

If you don't have Vino already, you will need to install the Vino tool and verify it and set the encryption to false so macOS Screen Sharing can see it.

sudo apt-get install vino gsettings set org.gnome.Vino require-encryption false gsetgsettings list-recursively org.gnome.Vino | grep encrypt org.gnome.Vino require-encryption false

Open the firewall for the screen sharing port.

sudo ufw allow from any to any port 5900 proto tcp Rules updated Rules updated (v6)

View the firewall settings, which show the VNC screen sharing port 5900, the ssh port 22 and Samba which we allowed earlier.

sudo ufw status Status: active To Action From -- ------ ---- 22/tcp ALLOW Anywhere Samba ALLOW Anywhere 5900/tcp ALLOW Anywhere 22/tcp (v6) ALLOW Anywhere (v6) Samba (v6) ALLOW Anywhere (v6) 5900/tcp (v6) ALLOW Anywhere (v6)

Or use the firewall GUI:

sudo apt install gufw gufw

If that doesn't work you can try installing the TightVNC server according to How to Install and Configure VNC on Ubuntu 22.04

sudo apt install xfce4 xfce4-goodies sudo apt install tightvncserver

Launch the VNC server using

vncserver

Configure the VNC server by stopping it first.

vncserver -kill :1

Edit the VNC configuration file.

seanoconnor:~/Desktop$ cat ~/.vnc/xstartup #!/bin/bash xrdb $HOME/.Xresources startxfce4 &

Save the original default file which is

seanoconnor:~/Desktop$ cat ~/.vnc/xstartup.bak #!/bin/sh xrdb "$HOME/.Xresources" xsetroot -solid grey #x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager & # Fix to make GNOME work export XKL_XMODMAP_DISABLE=1 /etc/X11/Xsession

Make the file executable and restart the VNC server

chmod +x ~/.vnc/xstartup vncserver -localhost

On the Mac Command Shift to bring up Spotlight Search and search for Screen Share.

Click Share Screen and enter the user name and password.

Alternatively you can do Control K on the Mac desktop background and screen share this way:

Here's the Ubuntu Linux screen share on the Mac,

Ubuntu Apps

Ubuntu comes with Thunderbird email among other applications. You can open Ubuntu Software in the Applications folder and search for more.

Install Gnome-Tweaks using the Ubuntu software app (shopping bag icon).

In the Settings you can launch apps upon startup,

Putting Apps on the Dock

Usually you can run an app from the terminal command line, and when it appears on the dock, you can right click its icon, select add to favorites and that will add it permanently to the dock.

But you might have to do this manually for some apps. For example, I downloaded the latest Blender version 3.3.0 for Linux, unpacked the download to create the Blender directory,

/home/seanoconnor/Desktop/blender-3.3.0-linux-x64

Then edit the blender.desktop in the Blender directory to point to the executable in the section Exec and the Blender icon in section Icon.

[Desktop Entry] Name=Blender GenericName=3D modeler ... GenericName[zh_TW]=3D 模型 Comment=3D modeling, animation, rendering and post-production ... Exec=/home/seanoconnor/Desktop/blender-3.3.0-linux-x64/blender %f Icon=/home/seanoconnor/Desktop/blender-3.3.0-linux-x64/blender.svg ... Terminal=false Type=Application Categories=Graphics;3DGraphics; MimeType=application/x-blender;

Copy the file to where Gnome can find it.

cp blender.desktop ~/.local/share/applications/

Launch Blender from the command line,

./blender

After Blender comes up, right click on its icon in the dock and select Add to Favorites (you may not have to do this). Now you should see the Blender icon permanently in the dock.

Running CanoScan LiDE 200 Flatbed Scanner

The CanoScan LiDE 200 flatbed scanner is no longer supported on macOS Monterey. But we can install and run it on Ubuntu using advice from Install Canon LiDE 300 / 400 on Ubuntu 18.4

First install the xsane software if you don't already have it:

sudo apt install xsane sudo apt install libsane-common sudo apt install sane-utils

Connect the scanner to a spare USB port on your PC. Run these tests to see if the scanner is connected and if you can scan at all:

sane-find-scanner # sane-find-scanner will now attempt to detect your scanner. If the # result is different from what you expected, first make sure your # scanner is powered up and properly connected to your computer. # No SCSI scanners found. If you expected something different, make sure that # you have loaded a kernel SCSI driver for your SCSI adapter. could not open USB device 0x1d6b/0x0003 at 004:001: Access denied (insufficient permissions) could not open USB device 0x1a2c/0x2124 at 003:003: Access denied (insufficient permissions) could not open USB device 0x093a/0x2533 at 003:002: Access denied (insufficient permissions) found USB scanner (vendor=0x04a9 [Canon], product=0x1905 [CanoScan], chip=GL847) at libusb:003:004 could not open USB device 0x1d6b/0x0002 at 003:001: Access denied (insufficient permissions) could not open USB device 0x1d6b/0x0003 at 002:001: Access denied (insufficient permissions) could not open USB device 0x1d6b/0x0002 at 001:001: Access denied (insufficient permissions) # Your USB scanner was (probably) detected. It may or may not be supported by # SANE. Try scanimage -L and read the backend's manpage. # Not checking for parallel port scanners. # Most Scanners connected to the parallel port or other proprietary ports # can't be detected by this program. # You may want to run this program as root to find all devices. Once you # found the scanner devices, be sure to adjust access permissions as # necessary. scanimage -L device `genesys:libusb:003:004' is a Canon LiDE 200 flatbed scanner # Simple scan to see if you can get an image at all. scanimage --format=png > test.png ; xdg-open test.png

Now run the nifty xsane scanning program which has a GUI. You can set the scanner resolution and color, preview scan, select the area to scan, do a hi-res scan and view the image.

xsane
Set Scanner Options - Scanning Preview - Select Area to Scan - Scan - View Scanned Image
Wifi Diagnostics

You can see what's happening with your WiFi communications with these two utilities. The first one is linssid

sudo apt install linssid sudo linssid # Need to use root.
linssid
nm-connection-editor # This will show a GUI with your WiFi settings.

Ubuntu Linux on a MacBook Air

This platform is a 2010 original MacBook Air. Follow the excellent Ubuntu Desktop Installation instructions.

Macbook Air

I downloaded the Ubuntu .iso file and created a USB flash drive. I powered up my MacBook with the USB drive inserted, and paused the boot sequence to select the USB drive as the boot drive. Then I installed Ubuntu according to the instructions. During Ubuntu install I select the option to erase the disk.

macOS

Well, macOS is Unix, so you get most of what you want out of the box. Note that macOS only supports 64-bit applications. There are also security features which you'll need to work around when running third party apps.

Working Around macOS Security

When you try to run a third party executable, e.g. ClozureCommonLisp, the OS will block it as follows in macOS:

Go to the Settings->Security and Privacy and allow the exe to run:

You can then open the exe:

PROGRAMMING TOOLS

Developer Tools Mac

Xcode

macOS X comes with most of the the Unix utilities make, diff, gcc, g++ (the clang equivalent), lldb, etc. already installed. You can install the free Xcode IDE from the Apple App Store

Install the command line tools also:

# You may have to install Xcode command line tools first. xcode-select --install

When you launch Xcode, it may ask you about which additional SDK's you wish to install and during setup it's got this new thing:

XCode Settings for a Command Line App in C++

I'll use my Primpoly app as an example. Create a new XCode project as a command line app in the C++ language. Add all the source code files into the project. Xcode will make copies in a subdirectory, so be aware you'll have to manually synchronize your master copies with Xcode's copies. Go to settings and change the locations for the products. XCode file locations XCode file locations

Add a new pre-build copy command to put the factor lookup tables in the same place as the executable by going to Product ➤ Scheme ➤ Edit Scheme ➤ Build ➤ pre-Actions and adding these commands:

cp -rf $PROJECT_DIR/../../../SourceCode/Primpoly/FactorTables $PROJECT_DIR/../Build/Products/Debug echo "$PROJECT_DIR for Primpoly = " $PROJECT_DIR › /tmp/temp.txt

X

Also in the scheme, set the arguments for the executable, X

Make sure your source code and other files is in the correct location (not grayed out) XCode source files

No more class browser in the new Xcode! The best you can do is right click on a class name, then use Find Expand the name in the finder window to see the class and its members. X X

Here is a clean-up bash script I use:

cat cleanupdate.sh #!/bin/bash # cleanupdate.sh printf "Clean up all Xcode files which are not needed\n" # You only need /Primpoly/Primpoly.xcodeproj which is the Xcode project # and /Primpoly which contains a duplicate copy of the source code. rm -rf Build rm -rf ModuleCache.noindex rm -rf Primpoly-cswhfrwgwdikgzfdpiorbeaiennz rm -rf SDKStatCaches.noindex rm -rf SymbolCache.noindex printf "Updating the source files\n" cp -rf ../../SourceCode/Primpoly/*.cpp Primpoly/Primpoly cp -rf ../../SourceCode/Primpoly/*.hpp Primpoly/Primpoly printf "Removing syntax colored source files\n" rm -rf Primpoly/Primpoly/*.html printf "Done!\n"

The new MacBook Pro is based on a 64-bit ARM CPU design and has a GPU on the same bus. Apple will automatically ask you to install Rosetta, which emulates the Intel CPU instruction set if you open an Intel App. Make sure you compile all source code to native ARM CPU code *.exe binaries, or you'll get a speed hit of 2X as your Intel binary is emulated on the ARM. You can look at info for any App to see if it is Universal (runs on Intel or Apple Silicon), Intel or Apple silicon).

Rosetta
Bash

The new macOS now uses zsh instead of bash (Apple Support: Use zsh as the default shell on your Mac) but you can install the latest version of bash and use it as your shell.

Download the Bash source code from Bash from GNU Web Site

Unpack the bash-5.1.tar file, move it to a convenient directory, cd into that directory, then run these commands,

cd /Users/seanoconnor/Desktop/Apps/Bash/bash-5.1 ./configure make sudo make install

This installs bash into both /usr/local/bin and /usr/local/bin:

seanoconnor@Seans-MBP Bash % /usr/local/bin/bash --version GNU bash, version 5.1.0(1)-release (aarch64-apple-darwin21.2.0) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Make the new version of bash your default shell for all terminals. First edit this file and add the new bash path at the top:

sudo vi /etc/shells 1 # List of acceptable shells for chpass(1). 2 # Ftpd will not allow users to connect who are not using 3 # one of these shells. 4 5 /usr/local/bin/bash 6 /bin/bash 7 /bin/csh 8 /bin/dash 9 /bin/ksh 10 /bin/sh 11 /bin/tcsh 12 /bin/zsh

Then change the default shell on the command line and in the Terminal Preferences

seanoconnor:~$ chsh -s /usr/local/bin/bash Changing shell for seanoconnor. Password for seanoconnor:

Close all terminal windows, open a terminal window up again, and check the version

seanoconnor:~$ echo $BASH_VERSION 5.1.0(1)-release
Brew

Brew installs other open source software on the Mac. (it's the macOS version of apt-get for Ubuntu Linux).

# Install brew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ==> Next steps: - Run these two commands in your terminal to add Homebrew to your PATH: echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/seanoconnor/.bash_profile eval "$(/opt/homebrew/bin/brew shellenv)" - Run brew help to get started - Further documentation: https://docs.brew.sh

Brew will add this last line to your .bash_profile.

eval "$(/opt/homebrew/bin/brew shellenv)"

Remove this line. Instead, integrate brew's path into your Bash Settings

# Update brew to the latest version. brew update --verbose # Error check your installation. You can ignore some of the warnings. brew doctor
rsync

Install rsync with brew.

brew install rsync brew upgrade rsync which rsync /opt/homebrew/bin/rsync rsync --version rsync version 3.2.3 protocol version 31 Copyright (C) 1996-2024 by Andrew Tridgell, Wayne Davison, and others. Web site: https://rsync.samba.org/
Ctags

Universal Ctags is a successor to Exuberant Ctags. First install Brew. Then install ctags,

brew install universal-ctags brew upgrade universal-ctags ctags --version Universal Ctags 6.1.0, Copyright (C) 2015-2024 Universal Ctags Team Universal Ctags is derived from Exuberant Ctags. Exuberant Ctags 5.8, Copyright (C) 1996-2024 Darren Hiebert Compiled: Mar 30 2024, 17:34:22 URL: https://ctags.io/ Output version: 0.0 Optional compiled features: +wildcards, +regex, +gnulib_fnmatch, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +yaml, +case-insensitive-filenames, +packcc, +optscript, +pcre2

If you have problems, uninstall,

brew uninstall universal-ctags

Then reinstall as above.

Developer Tools Ubuntu Linux

Naturally, you've got all the unix tools or can easily install them using sudo apt-get from the terminal.

Ctags

To install Universal Ctags on Ubuntu Linux, download several SW tools first, download the source code, build and install

sudo apt-get install git sudo apt install pkg-config sudo apt install pkgconf cd ~ git clone https://github.com/universal-ctags/ctags.git cd ctags ./autogen.sh ./configure make sudo make install ctags --help

Bash Settings

I'm using the bash shell in preference to the macOS default zsh. Read the Beginner's Guide, Tutorial, and Reference then go to your home directory, and place the bash startup files .bash_login, .bash_logout and .bashrc there.

I have lots of utilties and shortcuts in these scripts. I automatically detect whether I'm on a macOS or Linux system.

Here is my .bash_profile and .bashrc and .bash_logout

Git

I use Git for source code control. It's out of the box in macOS

git --version git version 2.44.0

But better you should install a recent version using brew

brew install git brew upgrade git git --version git version 2.45.2

Also install the large file version

brew install git-lfs brew upgrade git-lfs git-lfs --version git-lfs/3.5.1 (GitHub; darwin arm64; go 1.22.1)

Install in Ubuntu Linux using

sudo apt install git

It's described in the Git Pro 2 Book. Here's an example of how I set up my Git repository for my Primpoly project using local repositories.

Git Configuration

In your home directory ${HOME}, create the global git configuration file .gitconfig and the files-to-be-ignored file .gitignore_global

Ignore files won't show up as untracked when you do a git status

Local Protocol for the Git Repository

Create a local directory on your computer to serve as your remote git repository. This is the simplest possible remote protocol, and can be used if you are on a single computer or everyone remotely shares your directory.

cd ${web_dir} cd private mkdir repos cd repos

These are all remote repositories:

ls Art/ Crc/ FFT/ Life/ MaintainWebPage/ ParserGenerator/ Primpoly/ PrimpolyC/

In your .bashrc file in home directory, add the location of the local git repository,

# Location of git repository. export GITREPOS="${web_dir}/private/repos"

Let's add a new project Primpoly to the remote repository. The --bare flag says there are no files in this directory; it is only used as a central repository to push and pull from local working directories.

$ mkdir Primpoly $ cd Primpoly $ git --bare init Initialized empty Git repository in $web_dir/private/repos/Primpoly/ $ la HEAD branches/ config description hooks/ info/ objects/ refs/
Set up a Local Git Snapshot

Let's place a collection of C++ source files under source code control. Go to the local directory with the same name as the remote git repository. Run a git initialization script. This will create a new .git subdirectory.

$ cd ${web_dir}/Mathematics/AbstractAlgebra/PrimitivePolynomials/Project/SourceCode/Primpoly $ git init Initialized empty Git repository in /Users/seanoconnor/Desktop/Sean/WebSite/Art/.git/ $ ls .git HEAD config description hooks/ info/ objects/ refs/

Add the files to source code control.

cd ${web_dir}/Mathematics/AbstractAlgebra/PrimitivePolynomials/Project/SourceCode/Primpoly $ git add *.cpp *.h /FactorTables $ git status On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: FactorTables/c02minus.txt ... new file: FactorTables/c12plus.txt new file: Primpoly.cpp ... new file: ppUnitTest.h Untracked files: (use "git add <file>..." to include in what will be committed) Primpoly.cpp.html ... ppUnitTest.h.html

Your files are staged now. When ready, do a commit,

$ git commit -m "Initial import from SVN." [master (root-commit) 75fa9b1] Initial import from SVN. 32 files changed, 46548 insertions(+) create mode 100755 FactorTables/c02minus.txt ... create mode 100755 FactorTables/c12plus.txt create mode 100755 Primpoly.cpp ... create mode 100755 ppUnitTest.h

You can see your new branch and the history,

git branch * master $ git log commit 75fa9b1ef5b995c178e264d197c413f395221e4d Author: Sean E. O'Connor <seanerikoconnor@gmail.com> Date: Sun Aug 14 20:19:22 2016 -0700 Initial import from SVN.
Set up the Remote Repository

Now we let the local directory Primpoly know about the remote repository.

$ git remote add origin $GITREPOS/Primpoly/ $ git remote show origin $ git remote -v origin ${web_dir}/private/repos/Primpoly/ (fetch) origin ${web_dir}/private/repos/Primpoly/ (push)

Then we push up to the remote repository for the first time.

$ git push --set-upstream origin master Counting objects: 35, done. Delta compression using up to 8 threads. Compressing objects: 100% (35/35), done. Writing objects: 100% (35/35), 1.10 MiB | 0 bytes/s, done. Total 35 (delta 2), reused 0 (delta 0) To $GITREPOS/Primpoly/ * [new branch] master -> master

Verify the git repository is set up correctly by doing a test clone from the remote repository, and verify there are no differences between it and your local repository,

$ cd ~/Desktop $ git clone $GITREPOS/Primpoly Cloning into 'Primpoly'... done. $ diff -r ~/Desktop/Primpoly \ ~/Desktop/Sean/WebSite/Mathematics/AbstractAlgebra/ PrimitivePolynomials/Project/SourceCode/Primpoly
Copying over to Ubuntu and Fixing Up the Remote Repository

You can rsync the git repository and local files between macOS and Ubuntu Linux If you copy from macOS to Linux, the local git configuration file will point to the macOS home dir instead of the Linux home dir.

cat .git/config ... [remote "origin"] url = /Users/seanoconnor/Desktop/Sean/WebSite/private/repos/ParserGenerator/ ...

You can use a symbolic link to fix that by pointing Linux to the macOS type home directory.

cd ~ sudo ln -s home Users

You may also see the local files say they are changed. Just git restore them and pull again.

git status On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: Primpoly.c modified: Primpoly.h modified: ppArith.c modified: ppFactor.c modified: ppHelperFunc.c modified: ppIO.c modified: ppOrder.c modified: ppPolyArith.c git restore *.c git restore *.h git pull git status On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean
Some Git Commands

You can use macOS X mergetool/opendiff to resolve conflicts.

$ git mergetool

Clean up the local snapshot. Fetch all the remote branches and tags, reset, clean, and garbage collect.

git fetch --all --tag --prune git pull git reset --hard git clean -f git gc

A few informational commands.

# Which branches are in the local snapshot? git branch * master # Which branches are in the remote? git branch -r origin/master # What's history of the last three commits? git log -3 commit 6bf0fee39e38de15d2503a1c31d49184ea3eed25 (HEAD -> master, origin/master) Author: Sean E. O'Connor Date: Thu Oct 24 20:01:56 2024 -0700 Subclass TrialPolynomial from Polynomial base class commit d3693ba6971f81251f2b492251650461c7177c9b Author: Sean E. O'Connor Date: Sat Oct 12 17:37:17 2024 -0700 Clean up indentation so vim folding works correctly commit 3d5e6ea70a900b9e470a29735c311e993baff287 Author: Sean E. O'Connor Date: Tue Jul 2 20:58:16 2024 -0700 Automated update of Primpoly version to 16.3 # I don't have any tagged branches. git tag # What's the current status? Do I have any updated files? Pending commits? Etc. git status -v On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean

Check out a branch in the local repository as follows to make sure it tracks the remote branch upon creation:

git checkout -b Primpoly_experimental --track origin/Primpoly_experimental

After editing a file macLinuxComputerSetupForDevelopers.html in the local snapshot, check differences, add it for staging, create a commit, the push to the remote:

cd ~/Desktop/Sean/WebSite/ComputerScience/DevelopmentEnvironment git status On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: macLinuxComputerSetupForDevelopers.html no changes added to commit (use "git add" and/or "git commit -a") git add macLinuxComputerSetupForDevelopers.html git commit -m "Add a lot more git command examples" [master 0b267b4] Add a lot more git command examples 1 file changed, 228 insertions(+), 13 deletions(-) git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 10 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 3.03 KiB | 3.03 MiB/s, done. Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0) To /Users/seanoconnor/Desktop/Sean/WebSite/private/repos/DevelopmentEnvironment 97cf0ad..0b267b4 master -> master

Check out a tagged branch:

git checkout tags/Primpoly_release_100 -b Primpoly_release_100

Deleting a remote branch using the new way as of Git 1.7 which is git push origin --delete name_of_the_remote_branch

git push origin --delete seanoco/Primpoly_experimental

Did you try to push Primpoly.h to the remote branch but aborted becasuse the file was too large? Here's how to recover:

git rm --cached Primpoly.h git commit --amend -C HEAD

make

Get a new version of make which you can download. To install, do the usual GNU procedure,

cd /Users/seanoconnor/Desktop/Apps/Make/make-4.3 ./configure make sudo make install make --version GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i386-apple-darwin11.3.0

cmake

You will need to download and install CMake, then add the CMake binary to your path:

cat .bash_profile ... # CMake tool used for Blender. cmakebin="/Applications/CMake.app/Contents/bin/" PATH="\${HOME}:\${cmakebin}:${PATH}" ...
cmake --version cmake version 3.29.0 CMake suite maintained and supported by Kitware (kitware.com/cmake).

rsync

Download a new version of rsync. Unpack rsync-3.2.3.tar.gz file.

See the rsync INSTALL file for hints on how to install the missing libraries and/or how to generate (or fetch) man pages.

sudo apt install libxxhash-dev sudo apt install libzstd-dev sudo apt install liblz4-dev sudo apt install libssl-dev

Then configure, build and install rsync and check the version.

cd rsync-3.2.3/ ./configure make sudo make install which rsync /usr/local/bin/rsync rsync --version rsync version 3.2.3 protocol version 31

ack

ack does regular expression searches of files within directories recursively. Think of it as fast replacement for combining find and grep with more powerful (Perl style REs) and lots of ways to customize searches.

For example, here is the old way to search:

find . -name '*.html' -exec grep -H "ack.*html" {} \; ./ComputerScience/macLinuxComputerSetupForDevelopers.html: seanoconnor:~/Desktop/Sean/WebSite$ ack --html "find.*html.*grep"

And here is the ack way:

ack "ack.*html" ComputerScience/macLinuxComputerSetupForDevelopers.html 1282: seanoconnor:~/Desktop/Sean/WebSite$ ack --html "find.*html.*grep" ack --thpppt _   /| \'o.O' =(___)=    U ack --thpppt!

I downloaded the single Perl file version 3.7.0 of ack then made it available to where my PATH could find and run it,

mv ack-v3.7.0 ack chmod +x ack sudo mv ack /usr/local/bin

To tell ack which file types to search, put this setup file .ackrc into your home directory:

# Tell ack to search in C and Python files only. # See the manual at # https://beyondgrep.com/documentation/ack-v3.6.0-man.html # # Install ack as a Perl file from # https://beyondgrep.com/install/ # using # curl https://beyondgrep.com/ack-v3.6.0 > ack # chmod +x ack # sudo cp ack /usr/local/bin # # View the different file types with # # ack --help-types # --type=cc --type=cpp --type=python --type=html --type=css --type=make # To the existing file type cc, add .txt and .paths as a possible extension to enable searching *.txt files. --type-add=cc:ext:txt,log,paths,ipynb

PROGRAMMING LANGUAGES

C++ Language and Compilers

Start by reading the textbooks A Tour of C++ by Bjarne Stroustrup and The C++ Programming Language, 4th Edition then read the latest updates in the C++ Super-FAQ and the C FAQ

Photo of Bjarne Stroustrup.

Mac OS X development tools contain the clang C++ and C compilers. They come with Xcode.

Ubuntu Linux To get C++ and C working in Ubuntu Linux, you can use g++ which is installed already. Or you can install clang, but you have to explicity install its libraries,

sudo apt-get install clang sudo apt-get install libc++-dev sudo apt-get install libc++abi-dev

Then you can compile thus:

$ cat foo.cpp #include <string> #include <iostream> using namespace std; int main(int argc,char** argv) { string s(argv[0]); cout <<s <<endl; } $ clang++ -std=c++11 -stdlib=libc++ foo.cpp

If that doesn't work (but it should), change your makefiles by replacing the default library -stdlib=libc++, with the older GNU library -stdlib=libstdc++

# This is OK if we switch to the older GNU library. $ clang++ -std=c++11 -stdlib=libstdc++ foo.cpp

C++ GUIs

I haven't tried them yet but the C++ GUIs FoxTookit and WxWidgets sound interesting. WxWidgets looks a lot like Windows API with classes. Here is a tutorial ending up with source code for a tetris game.

LLDB Debugger

I use the lldb debugger in the llvm toolchain which comes installed on macOS.

# Load executable compiled with -g option. lldb Bin/Primpoly.exe (lldb) target create "Bin/Primpoly.exe" Current executable set to 'Bin/Primpoly.exe' (x86_64). # Set a breakpoint in the code. (lldb) b ppBigInt.cpp:433 Breakpoint 2: where = Primpoly.exe`BigInt::operator unsigned long() const + 18 at ppBigInt.cpp:433, address = 0x000000010000fa92 # Run the program. (lldb) run 2 4 Process 49251 launched: '/Users/seanoconnor/Desktop/Sean/WebSite/Mathematics/AbstractAlgebra/ PrimitivePolynomials/Project/Build/Bin/Primpoly.exe' (x86_64) Primpoly Version 16.3 - A Program for Computing Primitive Polynomials. Copyright (C) 1999-2024 by Sean Erik O'Connor. All Rights Reserved. ... Process 49251 stopped * thread #1: tid = 0x8a8db2, 0x000000010000fa92 Primpoly.exe` BigInt::operator unsigned long(this=0x00007fff5fbf8d18) const + 18 at ppBigInt.cpp:433, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1 frame #0: 0x000000010000fa92 Primpoly.exe`BigInt::operator unsigned long (this=0x00007fff5fbf8d18) const + 18 at ppBigInt.cpp:433 430 BigInt::operator ppuint() const 431 throw( BigIntOverflow, bad_exception ) 432 { -> 433 ppuint result = 0 ; 434 ppuint b = base_() ; 435 436 for (int i = static_cast<unsigned int> digit_.size()) - 1 ; i > 0 ; --i) # Backtrace (lldb) bt * thread #1: tid = 0x8a8db2, 0x000000010000fa92 Primpoly.exe `BigInt::operator unsigned long(this=0x00007fff5fbf8d18) const + 18 at ppBigInt.cpp:433, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1 * frame #0: 0x000000010000fa92 Primpoly.exe`BigInt::operator unsigned long (this=0x00007fff5fbf8d18) const + 18 at ppBigInt.cpp:433 frame #1: 0x00000001000dc1b9 Primpoly.exe`unitTest() + 16233 at ppUnitTest.cpp:641 frame #2: 0x0000000100000c89 Primpoly.exe`main(argc=3, argv=0x00007fff5fbff600) + 89 at Primpoly.cpp:162 frame #3: 0x00007fff934cd5ad libdyld.dylib`start + 1 # Step to next line. (lldb) n Process 49251 stopped * thread #1: tid = 0x8a8db2, 0x000000010000fa9d Primpoly.exe `BigInt::operator unsigned long(this=0x00007fff5fbf8d18) const + 29 at ppBigInt.cpp:434, queue = 'com.apple.main-thread', stop reason = step over frame #0: 0x000000010000fa9d Primpoly.exe`BigInt::operator unsigned long(this=0x00007fff5fbf8d18) const + 29 at ppBigInt.cpp:434 431 throw( BigIntOverflow, bad_exception ) 432 { 433 ppuint result = 0 ; -> 434 ppuint b = base_() ; 435 436 for (int i = static_cast<unsigned int> digit_.size()) - 1 ; i > 0 ; --i) 437 { # List breakpoints. (lldb) br l Current breakpoints: 1: file = 'ppBigInt.cpp', line = 433, locations = 1, resolved = 1, hit count = 1 1.1: where = Primpoly.exe`BigInt::operator unsigned long() const + 18 at ppBigInt.cpp:433, address = 0x000000010000fa92, resolved, hit count = 1 2: name = 'l', locations = 0 (pending) 3: name = 'list', locations = 0 (pending) 4: name = 'l', locations = 0 (pending) # Delete all breakpoints. (lldb) br del About to delete all breakpoints, do you want to do that?: ÆY/nÅ y All breakpoints removed. (4 breakpoints) # Print a value. (lldb) p digit_ (std::__1::vector<unsigned long, std::__1::allocator< unsigned long> >) $4 = size=4 { [0] = 4 [1] = 3 [2] = 2 [3] = 1

Python

Keep the tutorial and library reference handy. Or better yet, download the whole set.

If you program LISP already, Python is very similar.

Python on MacOS

On macOS don't use the shipping python. Go to the Python Web Site and download the latest version of Python.

Install SSL root certificates during the install.

Python 3 installs into /Library/Frameworks/Python.framework/Versions/3.13 The installer will prefix the Python 3 path to your existing path in your .bash_profile

# Setting PATH for Python 3.13 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.13/bin:${PATH}" export PATH

I don't like this so remove it and set up a custom .bash_profile to change the path in cleaner manner.

Check by running the command python3 -V that we call Python 3.13

Get the latest PIP and check the version.

python3 -m pip install --upgrade pip pip3 --version pip 24.3.1 from /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pip (python 3.13)

Installing a virtual environment.

pip3 install virtualenv

Create a virtual environment which uses Python 3.x in your home directory. Remove any old virtual environments first. This will create a hidden subdirectory .VENV.

cd rm -rf .VENV/ virtualenv -p python3.13 .VENV313

Activate it. You’ll get a command line prompt showing you are in the virtual environment with the version of Python you chose.

source ~/.VENV313/bin/activate (.VENV) seanoconnor:~$ python -V Python 3.13.0

For convenience, go into macOS Terminal ➤ Preferences ➤ Profiles to launch the virtual environment for the Ocean window profile.

To uninstall your Python virtual environment,

pip3 uninstall virtualenv
Python on Ubuntu Linux

On Ubuntu Linux install Python if you want the version which comes with Ubuntu.

sudo apt install python3 sudo apt update

If you want the lastest version on Ubuntu/Linux you can build from source code. You will also need to do this if jupyter lab crashes with an ssl error in pip. But first, load these libraries:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

Go to the Python web site and download source code. In your ~/Downloads folder unpack using

tar -xJf Python-3.13.tar.xz

Build using

cd Python-3.13/ ./configure --enable-optimizations make -j

When that's done, replace the system Python using the command

sudo make install

Check the version is the correct new version using

python3 -V

Install pip using

python3 -m pip install --upgrade pip

Install the virtual environment,

sudo apt install python3-virtualenv cd ~ virtualenv -p python3 .VENV

To enable the virtual environment in a terminal window, do this command,

source ~/.VENV/bin/activate (.VENV) seanoconnor:~$ python -V seanoconnor:~$ python -V Python 3.13 seanoconnor:~$ pip --version pip 22.0.2 from /home/seanoconnor/.VENV/lib/python3.13/site-packages/pip (python 3.13)

Deactivate the virtual environment using

(.VENV) seanoconnor:~$ deactivate

For Python 3.x, install SSL root certificates, and install numpy, matplotlib, and other useful packages. See installing Python packages below for details.

Similarly to setting up .bash_profile for Python in macOS edit the code in your .bash_profile to set the path to Python 3.x On my Ubuntu Linux I've wired the bash profile script to automatically launch each new instance of terminal window in the Python virtual environment.

Installing Python Packages

You might as well upgrade pip then install every Python math library you need,

python3 -m pip install --upgrade pip pip3 install certifi # Python HTTPS certificates. pip3 install numpy # Vector and array library. See https://numpy.org pip3 install scipy # Python scientific library. See https://scipy.org pip3 install sympy # Symbolic math package. See https://www.sympy.org/en/index.html pip3 install seaborn # Statistical visualization using matplotlib. See https://seaborn.pydata.org pip3 install statsmodels # M-estimators robust regression, https://www.statsmodels.org/stable/index.html pip3 install matplotlib # Plotting. See https://www.statsmodels.org/stable/index.html pip3 install pandas # Data analysis. See https://pandas.pydata.org/ pip3 install ipython # Interactive python shell. See https://pypi.org/project/ipython/ pip3 install notebook jupyter # https://jupyter.org/install.html pip3 install jupyterlab # Jupyter notebook improved interface (can debug Python!) pip3 install --upgrade jupyterlab-vim # VIM keycap bindings to JupyterLab pip3 install nbconvert # Forjupyter nbconvert mynotebook.ipynb --to html pip3 install pyaml # Python version of JSON. See https://pypi.org/project/pyaml/ pip3 install opencv-python # Computer vision library. See https://opencv.org pip3 install scikit-image # Image processing in Python. See https://scikit-image.org pip3 install scikit-learn # Machine learning: NN, SVM, random forest, logistic regression, CART, Naive Bayes, PCA. See https://scikit-learn.org/stable/ pip3 install deepdiff # Recursive deep difference for Python objects. See https://pypi.org/project/deepdiff/0.2.0/ pip3 install bitarray # Boolean bits. See https://pypi.org/project/bitarray/ pip3 install Pygments # Code formatting. LaTeX uses this in their mint package. See https://pypi.org/project/Pygments/ pip3 install pyyaml # YAML file parser. See https://pypi.org/project/PyYAML/ pip3 install pylint # Python code lint See https://pypi.org/project/pylint pip3 install autopep8 # Python code formatter for PEP 8 style. See https://pypi.org/project/autopep8/

Keras and TensorFlow are optional.

pip3 install keras # Neural Net front end. pip3 install tensorflow # TensorFlow Neural Net architecture. (This will take a while). pip3 install pydot # For TensorFlow NN plotting utils.

You can verify which PIP modules you have installed:

pip3 list -v ... pycparser 2.22 /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages pip Pygments 2.18.0 /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages pip pylint 3.2.3 /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages pip ...

You can save the list of all your PIP modules and their versions to a file, so someone else can mirror your environment.

pip3 freeze > requirements.txt cat requirements.txt . . . pycodestyle==2.11.1 pycparser==2.22 Pygments==2.18.0 pylint==3.2.3 pyparsing==3.1.2 . . .

If you are using a virtual environment, you are in a separate sandbox, so to speak. Go into the VENV, do the pip upgrade, install all packages again, using the requirements file:

source ~/.VENV/bin/activate (.VENV) seanoconnor:~$ pip3 install --upgrade pip (.VENV) seanoconnor:~$ pip3 install -r requirements.txt

You can actually source level debug a package. Let's try this for NumPy First get the package information, then go to the source code location.

pip show mpmath Name: mpmath Version: 1.3.0 Summary: Python library for arbitrary-precision floating-point arithmetic Home-page: http://mpmath.org/ Author: Fredrik Johansson Author-email: fredrik.johansson@gmail.com License: BSD Location: /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages Requires: Required-by: sympy cd /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/mpmath ls -1 __init__.py __pycache__/ calculus/ ctx_base.py ctx_fp.py ctx_iv.py ctx_mp.py ctx_mp_python.py function_docs.py functions/ identification.py libmp/ math2.py matrices/ rational.py tests/ usertools.py visualization.py

Let's say you want to put a breakpoint in the norm function in the matrix package. insert a debug statement into the source code /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/mpmath/matrices/matrices.py in the function norm

. . . def norm(ctx, x, p=2): . . . # Insert this function to stop here and call the Python debugger! breakpoint() . . . try: iter(x)

When you call the norm function, you will hit the breakpoint and enter the debugger:

seanoconnor:~$ python3 . . . >>> import mpmath as mp >>> x = mp.matrix([-10,2,100]) >>>; mp.norm(x) > /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/mpmath/matrices/matrices.py(936)norm() -> breakpoint() (Pdb) l 931 mpf('100.0') 932 933 """ 934 935 # Insert this function to stop here and call the Python debugger! 936 -> breakpoint() 937 938 try: 939 iter(x) 940 except TypeError: 941 return ctx.absmax(x) (Pdb) p x matrix( [['-10.0'], ['2.0'],
PyCharm

I use the free community edition of PyCharm IDE on my Apple Silicon M1 MacBook Pro.

Do the trust thing,

To create a new project from an existing file do File->Open and select the file.

Let's assume you've set up a Python virtual environment. Select which Python interpreter to use in the PyCharm settings. Click on Show All interpreters, then + to add the Python exe.

Edit the configuration to put in command line arguments for your script.

Remarks

  • You need to define a main() function or PyCharm won't run.
  • If you get the error saying the SDK cannot be written to, try deleting all the Python interpreters in the list except the one you are using.
  • You can format the source code to the Python PEP standard!

You can do source level debugging in the IDE and code inspection and refactoring.

Debugging Python on the Command Line

In this example, we use my program updateweb.py The program has been set up to either run from the command line or as a module.

if __name__ == '__main__': """Python executes all code in the file, so all classes and functions get defined first. Finally we come here. If we are executing this file as a Python script, the name of the current module is set to main, thus we'll call the main() function.""" main() else: """When using as a module, start python, then import the module and call it: python import updateweb updateweb.main(["--test"]) Or if you want to debug, do this: python import pdb import updateweb pdb.run('updateweb.main(["--test"])') b updateweb.main c <Now use n to step, l to list, etc> """ pass

Run Python and import the debugger module, and the entire script itself

seanoconnor:~/Desktop/Sean/WebSite/WebDesign/MaintainWebPage$ python Python 3.9.3 (v3.9.3:e723086bc3, Apr 2 2021, 08:25:55) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pdb >>> import updateweb

Set up the debugger to run starting in the main() function with arguments,

>>> pdb.run('updateweb.main(["--test"])')

Set a breakpoint in main

(Pdb) b updateweb.main Breakpoint 1 at /Users/seanoconnor/Desktop/Sean/WebSite/WebDesign/MaintainWebPage/updateweb.py:554

Start running the program. We stop at the breakpoint,

(Pdb) c > /Users/seanoconnor/Desktop/Sean/WebSite/WebDesign/MaintainWebPage/updateweb.py(558)main() -> print("""

List the source lines around the breakpoint

(Pdb) l 553 554 B def main(raw_args=None): 555 """Main program. Clean up and update my web site.""" 556 557 # Print the obligatory legal notice. 558 -> print(""" 559 updateweb Version 7.1 - A Python utility program which maintains my web site. 560 Copyright (C) 2007-2024 by Sean Erik O'Connor. All Rights Reserved. 561 562 It deletes temporary files, rewrites old copyright lines and email address 563 lines in source files, then synchronizes all changes to my web sites. (Pdb)

Print a variable

(Pdb) p raw_args ['--test']

Backtrace shows the calling stack,

(Pdb) bt /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/bdb.py(580)run() -> exec(cmd, globals, locals) <string>1)<module>() > /Users/seanoconnor/Desktop/Sean/WebSite/WebDesign/MaintainWebPage/updateweb.py(581)main() -> CommandLineSettings(user_settings, raw_args )

See (Pdb) help and the Online Python Manual for more information.

Debugging PIP Python Packages

Let's debug Pygments, the Python syntax highlighter. First gather information on it:

pip show Pygments Name: Pygments Version: 2.18.0 Summary: Pygments is a syntax highlighting package written in Python. Home-page: https://pygments.org Author: Author-email: Georg Brandl License: BSD-2-Clause Location: /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages Requires: Required-by: ipython, jupyter-console, nbconvert, qtconsole

This tells us the Pygments source code location.

cd /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages cd pygments ls __init__.py __pycache__/ console.py filters/ formatters/ lexers/ plugin.py scanner.py style.py token.py util.py __main__.py cmdline.py filter.py formatter.py lexer.py modeline.py regexopt.py sphinxext.py styles/ unistring.py

Now lets add a breakpoint to the source code file pygments/lexers/python.py the new way:

class PythonLexer(RegexLexer): """ For Python source code (version 3.x). .. versionchanged:: 2.5 This is now the default ``PythonLexer``. It is still available as the alias ``Python3Lexer``. """ # Set a breakpoint. breakpoint() name = 'Python'

And now when we run my syntax coloring Python script, it stops at the breakpoint!

> /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/pygments/lexers/python.py(37)PythonLexer() -> name = 'Python' (Pdb) l 32 """ 33 34 # Set a breakpoint. 35 breakpoint() 36 37 -> name = 'Python' 38 url = 'https://www.python.org' 39 aliases = ['python', 'py', 'sage', 'python3', 'py3', 'bazel', 'starlark'] 40 filenames = [ 41 '*.py', 42 '*.pyw', (Pdb) c Highlighting the syntax for file syntax_highlighter.py Deciding on a lexer for syntax_highlighter Chose the lexer <pygments.lexers.PythonLexer> Read the file syntax_highlighter.py into memory Wrote the syntax highlighted file syntax_highlighter.py.html into disk

Common Lisp

LISP is always ten years ahead at any given time.

Ubuntu Linux

sudo apt-get install sbcl

Macs Download the install package for the binary from Steel Bank Common Lisp. Unpack and follow instructions.

cd ~/Desktop/Apps/SBCL/sbcl-2.1.2-arm64-darwin sudo sh install.sh Password: ... /usr/local make: Entering directory '/Users/seanoconnor/Desktop/Apps/SBCL/sbcl-2.1.2-arm64-darwin/contrib/asdf' SBCL has been installed: binary /usr/local/bin/sbcl core and contribs in /usr/local/lib/sbcl/ Documentation: man /usr/local/share/man/man1/sbcl.1

Once installed, you'll get a bare-bones command line REPL. Try running $ sbcl from the command line and try

(car '(a b c)) (cdr '(a b)) (cons 'a '(b c)) (quit)

You can also run a LISP script from file directly:

cat hello.lsp #!/usr/local/bin/sbcl --script ; Shebang to call the LISP interpreter for this file. ; Do chmod 755 hello.lsp to make the file executable. ; ; hello.lsp ; A simple LISP test program. ; Print a string to the console. (write-line "Hello, World!") ; Convert a LISP list to a string. (defun list-to-string (lis) (format nil "~A" lis)) ; Function which prints a LISP expression and its evaluation to the console. (defun show-example( x ) (write-line (list-to-string `(,x => ,@(eval x))))) ; Print this example: ; (((LAMBDA (X) (1+ X)) 2) => . 3) (show-example '( (lambda(x) (1+ x)) 2) ) (show-example '(defvar dog)) (show-example '(setf dog '(husky))) (show-example 'dog)
./hello.lisp Hello, World! (((LAMBDA (X) (1+ X)) 2) => . 3) ((DEFVAR DOG) => . DOG) ((SETF DOG '(HUSKY)) => HUSKY) (DOG => HUSKY)

For convenience, I load my Common LISP parser generator project in the SBCL startup file .sbclrc

(load "LR(1)AndLALR(1)ParserGenerator.lsp") (load "LR(1)AndLALR(1)Parser.lsp") (test-parser-generator) (test-parser)

However, your life will be much easier if youw download and install Slime Unpack and install the slime directory in /Applications/slime then install this .emacs file in your home directory:

(setq inferior-lisp-program "/usr/local/bin/sbcl") (add-to-list 'load-path "/Applications/slime") (require 'slime) (slime-setup)

Vim, Ctags, Emacs, Slime, Steel Bank Common Lisp.

You should also install Emacs Invoke Emacs and with the command M-x slime go into Lisp interaction mode. Useful REPL commands are Control-c Control-p to move back one prompt, Control-c Control-n to move forward, Control-a and Control-e to go to beginning and end of the line, Control-x o to switch between buffers, Control-C Control-D d to lookup documentation for a symbol, and Control-X Control-S to exit emacs.

For LISP tutorials and references online see

I've also used CLISP

Perl

I was programming in Perl and switched over to Python after discovering this article.

FORTRAN

The first language I learned was FORTRAN from Bill Joy at U. C. Berkeley!

Berkeley Computing Center Punched card circa 1975.

It now has object oriented programming!

On Ubuntu Linux install GNU Fortran using

sudo apt-get install gfortran

Here's a sample program

$ cat circle.f90 ! A module containing classes. module class_Circle implicit none private real :: pi = 3.1415926535897931d0 ! Module-wide private constant ! Circle class. type, public :: Circle ! Member variable. real :: radius contains ! Member functions defined here but implemented elsewhere in the module. procedure :: area => circle_area procedure :: print => circle_print end type Circle ! Circle member functions implemented here. contains function circle_area( this ) result( area ) class( Circle ), intent( in ) :: this real :: area area = pi * this%radius ** 2 end function circle_area subroutine circle_print(this) class( Circle ), intent( in ) :: this real :: area area = this%area() ! Call the type-bound function print *, 'Circle: r = ', this%radius, ' area = ', area end subroutine circle_print end module class_Circle program circle_test use class_Circle ! Use the classes in the module. implicit none type( Circle ) :: c ! Declare a variable of type Circle. c = Circle( 1.5 ) ! Use the implicit constructor, radius = 1.5. call c%print ! Call the type-bound subroutine end program circle_test

Build it and run it!

$ gfortran circle.f90 -o circle ./circle Circle: r = 1.50000000 area = 7.06858349

Math Software

There are a number of free alternatives to MATLAB and Mathematica for symbolic and matrix computation.

SciPy

SciPy is a scientific math suite for Python.

Here's how to install on Mac.

python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose statsmodels

You can list the packages installed using either python -m pip list or pip list.

pip list Package Version ----------------------- cycler 0.10.0 kiwisolver 1.1.0 matplotlib 3.1.2 numpy 1.17.4 pandas 0.25.3 patsy 0.5.1 pip 19.3.1 pyparsing 2.4.5 python-dateutil 2.8.1 pytz 2019.3 scipy 1.3.3 setuptools 42.0.2 six 1.13.0 statsmodels 0.10.2

To uninstall a package, for example, numpy, do

pip uninstall numpy

Here's an example taken from Normality Tests in Python Run python from the command line and type in these commands:

import numpy as np from numpy import mean from numpy import std from matplotlib import pyplot from statsmodels.graphics.gofplots import qqplot from scipy.stats import shapiro from scipy.stats import normaltest from scipy.stats import anderson # I generated random numbers from a N( 0, 10^2 ) distribution using the Box-Muller-Marsaglia method. NormalDeviatesList = [ -9.594, -6.614, 7.974, 8.959, 26.220, -11.746, -16.308, ... # Map to an np array type. NormalDeviatesArray = np.array( NormalDeviatesList ) # Mean and standard deviation look OK. mean(NormalDeviatesArray) -0.10023199999999999 std(NormalDeviatesArray) 9.95592528857946 # Plot a histogram and QQ plot. pyplot.hist(NormalDeviatesArray) pyplot.show() qqplot(NormalDeviatesArray, line='s') pyplot.show() # Run a few Normality tests. stat, p = shapiro(NormalDeviatesArray) stat 0.9996619820594788 p 0.5912390351295471 # So failed to the reject Normal hypothesis at 5% level using Shapiro-Wilks test. stat, p = normaltest(NormalDeviatesArray) stat 1.2465252328072989 p 0.5361921912564886 # So again, failed to the reject Normal hypothesis at 5% level using D’Agostino’s K^2 Test. result = anderson(NormalDeviatesArray) print('Statistic: %.3f' % result.statistic) Statistic: 0.350 p = 0 for i in range(len(result.critical_values)): sl, cv = result.significance_level[i], result.critical_values[i] if result.statistic < result.critical_values[i]: print('%.3f: %.3f, data looks normal (fail to reject H0)' % (sl, cv)) else: print('%.3f: %.3f, data does not look normal (reject H0)' % (sl, cv)) 15.000: 0.576, data looks normal (fail to reject H0) 10.000: 0.655, data looks normal (fail to reject H0) 5.000: 0.786, data looks normal (fail to reject H0) 2.500: 0.917, data looks normal (fail to reject H0) 1.000: 1.091, data looks normal (fail to reject H0)

Normal Histogram

QQ Plot

Sympy

Sympy is a symbolic math package built on top of Python.

Here's how to install on Mac.

First install mpmath by doing

git clone https://github.com/fredrik-johansson/mpmath.git cd mpmath git pull sudo python setup.py install
Then install sympy by doing
git clone https://github.com/sympy/sympy.git cd sympy git pull sudo python setup.py install
To do plotting, install matplotlib by doing,
python -mpip install -U matplotlib
Test by running Python, importing sympy and running a few commands,
python >>> from sympy import * >>> init_printing() >>> x = Symbol('x') >>> f = Function('f') >>> f = sin(x) >>> diff(f,x) cos(x) >>> integrate(f,x) -cos(x) >>> f.series(x,0,10) x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 + O(x**10) >>> a = Symbol('a') >>> b = Symbol('b') >>> c = Symbol('c') >>> d = Symbol('d') >>> m = Matrix( [[ a, b] , [c, d] ] ) >>> m ⎡a b⎤ ⎢ ⎥ ⎣c d⎦ >>> m.eigenvals() ⎧ _________________________ _________________________ ⎫ ⎪ ╱ 2 2 ╱ 2 2 ⎪ ⎨a d ╲╱ a - 2⋅a⋅d + 4⋅b⋅c + d a d ╲╱ a - 2⋅a⋅d + 4⋅b⋅c + d ⎬ ⎪─ + ─ - ────────────────────────────: 1, ─ + ─ + ────────────────────────────: 1⎪ ⎩2 2 2 2 2 2 ⎭ >>> m * (m ** -1) ⎡ a⋅d b⋅c ⎤ ⎢───────── - ───────── 0 ⎥ ⎢a⋅d - b⋅c a⋅d - b⋅c ⎥ ⎢ ⎥ ⎢ a⋅d b⋅c ⎥ ⎢ 0 ───────── - ─────────⎥ ⎣ a⋅d - b⋅c a⋅d - b⋅c⎦ >>> simplify( m * (m ** -1)) ⎡1 0⎤ ⎢ ⎥ ⎣0 1⎦

And here's a simple plot,

>>> plot(x**2,(x,-1,1))

Sympy plot( x**2, (x,-1,1))

Octave

Octave is a free MATLAB clone.

Run Octave.app from /Applications. It comes up in a terminal window. In the window, cd to your working directory containing your MATLAB .m files. Type the name of your MATLAB function or type the name of the .m file if you have just an inline main program.

SageMath

SageMath is a free mathematics software system comparable to Mathematica. You interact with it using the Jupyter notebook interface. You'll want to use JupyterLab as the IDE for SageMath. So make sure to install Python and also Jupyter Lab and its helper packages in Python packages.

On Mac follow the download instructions on the Sage Math web site.

On Ubuntu Linux install using

sudo apt-get install sagemath

On Mac launch the SageMath macOS app using Jupyter Lab X

On Ubuntu Linux launch using the command

sage --notebook

You may need to change the Jupyter Lab kernel explicitly to the SageMath engine. Go to Kernel ➤ Change Kernel ➤ Select Kernel X

What's going on here is that Jupyter notebooks look for a language to execute their code listings. This is usually Python, but can be SageMath in our case. You can view which kernels are available and which are active:

jupyter kernelspec list Available kernels: python3 /Library/Frameworks/Python.framework/Versions/3.13/share/jupyter/kernels/python3 sagemath-10.2 /usr/local/share/jupyter/kernels/SageMath-10.2 sagemath-9.7 /usr/local/share/jupyter/kernels/SageMath-9.7 cat /Library/Frameworks/Python.framework/Versions/3.13/share/jupyter/kernels/python3/kernel.json { "argv": [ "python", "-m", "ipykernel_launcher", "-f", "{connection_file}" ], "display_name": "Python 3 (ipykernel)", "language": "python", "metadata": { "debugger": true }

You can switch the editor to use VIM commands in Settings ➤ Enable Notebook Vim Mode

I've used it on my primitive polynomial finder

R

R is a statistical and plotting language.

For the Mac you can Download R as a package. Be sure to check the signature of the *.pkg file before you install it.

pkgutil --check-signature R-3.6.0.pkg Package "R-3.6.0.pkg": Status: signed by a certificate trusted by macOS Certificate Chain: 1. Developer ID Installer: Simon Urbanek (VZLD955F6P) SHA1 fingerprint: 7B 6B 81 12 E6 26 8C 16 F8 D4 ----------------------------------------------- 2. Developer ID Certification Authority SHA1 fingerprint: 3B 16 6C 3B 7D C4 B7 51 C9 FE ----------------------------------------------- 3. Apple Root CA SHA1 fingerprint: 61 1E 5B 66 2C 59 3A 08 FF 58 md5 R-3.6.0.pkg MD5 (R-3.6.0.pkg) = 64ede92058dde6c4e4c2c11e0ba8a60c
Once installed, run on the command line. I found out we can use equals for variable assignment (see below).
R R version 3.6.0 (2019-04-26) -- "Planting of a Tree" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin15.6.0 (64-bit) > x = c( 1, 2, 3, 4, 5, 6, 7 ) > var(x) [1] 4.666667 > mean(x) [1] 4 > sum(x) [1] 28 > 2 * x [1] 2 4 6 8 10 12 14
Read Introduction to R

EDITORS

VIM Programmer's Editor

Download gvim from Vim for Mac and Ubuntu Linux. Don't forget the Vim User Manual and tutorial.

Don't forget to define the gvim function in your .bash_profile.

In Ubuntu Linux install gvim like this:

sudo apt install vim-gtk3

I've customized the Vim GUI in the startup file .vimrc and added lots of hotkeys for custom text rewriting using Vimscript. Learn Vimscript the Hard Way and Learn X in Y minutes Where X=Vimscript Use :help on the Vim command line for reference. which lives in the home directory ~ on Mac or Ubuntu Linux.

Here is my .vimrc

Searching Multiple Files in Vim

For example, to search all *.cpp files in the current directory for the word static_cast, do this on the vim command line:

:vimgrep /static_cast/ **/*.cpp :copen 20

You can then go to the line containing the pattern you want and hit return to go to the file.

Searching Patterns in Multiple Files in Vim

Or better yet, you can use ack instead of grep for searches using the ack.vim plugin

File Differences in Vim
To do file differences, load the first file, ignore whitespace with :diffopt=iwhite, then do :diffsplit <second file name>. :diffupdate will resync if needed.

LibreOffice - Free Replacement for Microsoft Office

LibreOffice is free office suite compatible with Microsoft Office. Their apps can replace Excel, Word and PowerPoint. There are also Math and Database apps. LibreOffice apps can read Excel, Word and PowerPoint files, but may not be able to write recent versions of the file format. Say "yes" when the installer asks for permission to install and "yes" when LibreOffice asks to view documents in your directory.

ΤεΧ

For macOS download an install bundle from the MacTex TeX User's Group,

For Ubuntu Linux install using the install instructions,

sudo apt install texlive-latex-extra

Then try it out on a LaTeX file by processing it to a .pdf

pdflatex MortgageLoanDerivation.tex

View the .pdf file with either

evince MortgageLoanDerivation.pdf

or

xdg-open MortgageLoanDerivation.pdf

Be sure to read the quickie introduction A (Not So) Short Introduction to LATEX2ε

Art Software

GIMP Paint Program

Similar to Adobe Photoshop with paint tools and layers, but free, GIMP runs on both Mac and Ubuntu Linux download it and its documentation from Gimp

Gimp

In Ubuntu Linux install with

sudo apt-get install gimp

Blender

Blender is a free 3D rendering and animation tool. I have a worked example on my art page.

Inkscape

I use Inkscape to do the drawing and generate SVG files. Inkscape

To install on Ubuntu Linux,

sudo apt install inkscape

Right click on the Dash, and Add to Favorites

INTERNET

Netzero ISP

I used connect to the internet through the dialup telephone line using Netzero but now I use AT&T Uverse.

FTP

I use the free FTP client FileZilla.

On Ubuntu Linux install using
sudo apt install filezilla

Web Browsers

Download the browsers Firefox, (Turn off Settings ➤ Privacy & Security ➤ Website Advertising Preferences) DuckDuckGo, Opera and Chromium browsers. Safari comes with MacOS.

Email Clients

On Ubuntu Linux install Thunderbird email,
sudo apt-get install thunderbird

On macOS download and install the *.dmg for Thunderbird and follow the instructions to set up your email account.

Downloading a Local Copy of All Your Emails from Google Gmail and How To View Them

You can download all of your emails from your Gmail account and view them locally on your computer. This will give you a safe archive of all your emails.

  1. Follow the instructions in How to download your Google data Google will send an email when the download is ready with a link to your files. Files will be in *.mbox.zip format, which you can unpack. You can view the emails using Thunderbird.
  2. Create a new email account in Thunderbird. It does not have to be your Gmail account; I used my Microsoft hotmail account. You need to do this before you can import your mbox files into Thunderbird.
  3. Install the following Thunderbird add-on: thunderbird-find-add-on thunderbird-install-add-on
  4. Import the mbox files into your local mail folder with this add-on. thunderbird-import-mbox-files thunderbird-imported-mbox-files
  5. Now you can see all your old emails! thunderbird-imported-emails

Zoom

Install Zoom client for virtual meetings with other humans.

Antivirus for Mac

Install free Avast Antivirus Mac because it's prudent.

avast antivirus

GAMES

Stellarium

Stellarium is a free planetarium program.

On Ubuntu Linux install using
sudo apt install stellarium

Red Pill Screen Saver

Get the source code from GitHub opx3 / RedPill2. You can clone the repository using

git clone https://github.com/opx3/RedPill2.git

Build in XCode in Release mode. Let XCode update your settings. Double click on RedPill.saver to load it.

Exif Metadata Read/Write Tool

Exiftool lets you view and rewrite metadata in files. For a book in PDF format, the title will be the file name and the author will be read from the metadata. Set the author using the command

exiftool -author="Wald, R" *.pdf

APPENDIX

Installing Ubuntu Linux on a 2009 17 Inch MacBook

Too slow to really be useful, but here for fun.

Macbook Macbook
Preliminaries

I will install on an old MacBook Pro (17-inch, Early 2009) running OS X El Capitan Version 10.11.6 (15G31).

Macbook

You can read through these excellent guides on Install Linux on a Mac and how to dual boot Linux and macOS I took a little from both and from the Ubuntu web site documentation.

Installing the Boot Loader

The Mac's own boot manager has problems recognizing the Ubuntu OS. Thus you need to install a third party EFI (Extensible Firmware Interface) boot manager to be able to dual boot the Mac into Ubuntu or macOS. Visit the rEFInd Boot Manager Web Page. Download rEFIfind version refind-bin-0.11.2.zip

Downloading rEFFind

Disable SIP (System Integrity Protection) so you can install the boot loader. Shut down the Mac for 30 seconds. Then reboot in recovery mode. You can hold down the Option key and select the Recovery Disk. Select Terminal from the OSX Utitities menu bar and type csrutil disable. Then reboot again.

Unzip and install. You'll see I've already installed it once before.rEFInd

Gauss:refind-bin-0.11.2 sean$ sudo ./refind-install ShimSource is none Installing rEFInd on OS X.... Installing rEFInd to the partition mounted at /Volumes/ESP Found rEFInd installation in /Volumes/ESP/EFI/refind; upgrading it. Found suspected Linux partition(s); installing ext4fs driver. Installing driver for ext4 (ext4_x64.efi) Copied rEFInd binary files Notice: Backed up existing icons directory as icons-backup. Existing refind.conf file found; copying sample file as refind.conf-sample to avoid overwriting your customizations.

Now Shut Down your Mac.

Disk Drive and Partitions

Bring up the Disk Utility and resize your macOS partition smaller to give more room to Ubuntu. If you have extra non-contiguous partitions which you cannot merge, you can at least format them as ExFat so Linux can see them later.

In detail, here are our disk partititions,

Seans-MBP:~ sean$ diskutil list /dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *320.1 GB disk0 1: EFI EFI 209.7 MB disk0s1 2: Linux Filesystem 130.0 GB disk0s2 3: Linux Swap 9.7 GB disk0s3 4: Apple_HFS Recovery HD 650.0 MB disk0s4 5: Microsoft Basic Data Untitled 100.5 GB disk0s5 6: Apple_Boot Recovery HD 650.0 MB disk0s6 7: Apple_CoreStorage Gauss 77.7 GB disk0s7 8: Apple_Boot Recovery HD 650.0 MB disk0s8 /dev/disk1 (internal, virtual): #: TYPE NAME SIZE IDENTIFIER 0: Apple_HFS Gauss +77.3 GB disk1 Logical Volume on disk0s7 D016C459-3197-4791-9145-96EF497E4E65 Unlocked Encrypted Seans-MBP:~ sean$ diskutil listFilesystems Formattable file systems These file system personalities can be used for erasing and partitioning. When specifying a personality as a parameter to a verb, case is not considered. Certain common aliases (also case-insensitive) are listed below as well. ------------------------------------------------------------------------------- PERSONALITY USER VISIBLE NAME ------------------------------------------------------------------------------- ExFAT ExFAT Free Space Free Space (or) free MS-DOS MS-DOS (FAT) MS-DOS FAT12 MS-DOS (FAT12) MS-DOS FAT16 MS-DOS (FAT16) MS-DOS FAT32 MS-DOS (FAT32) (or) fat32 HFS+ macOS Extended Case-sensitive HFS+ macOS Extended (Case-sensitive) (or) hfsx Case-sensitive Journaled HFS+ macOS Extended (Case-sensitive, Journaled) (or) jhfsx Journaled HFS+ macOS Extended (Journaled) (or) jhfs+
Create a Bootable Ubuntu USB Stick

Download Ubuntu Desktop, version Ubuntu 22.04.1 LTS (Jammy Jellyfish). You'll get a file in your Downloads folder called ubuntu-22.04.1-desktop-amd64.iso

Create a Bootable USB Stick for Mac. I'll go through a worked example below.

You'll need a 2GB USB thumb drive or larger. Insert it and bring up Disk Utility with the option of Show All Devices

Select the device, not the volume. Make sure it's NOT you hard drive or backup drive!

Now erase the disk specifying format = MS-DOS (FAT) and Scheme = GUID Partition Map

Next, install the open source utility Etcher, downloading the version for macOS.

Now run it, selecting the Ubuntu ISO file and the thumb drive the push Flash. Etcher will ask for your system password and give you an estimated time.

After completion, select Eject

Install Ubuntu

Connect an Ethernet cable to your Internet Service Provider and the other end to your Mac; use a USB to Ethernet dongle if you don't have a native Ethernet port on your Mac.

Plug the USB drive containing the Ubuntu Linux distribution into your Mac. Restart your Mac. If you installed rEFInd the boot manager will automatically appear. Select the EFI Boot icon from the list in the boot device menu.

If you have a problem seeing the boot manager, or if you already have done an Ubuntu installation do this: as soon as the Mac starts to boot up, hold down the Option key. Keep holding it down until you see the Mac's boot manager display a list of available devices you can start up from. Select the EFI Boot icon from the list in the boot device menu.

Now go through the Ubuntu installation process.

You'll see either This computer currently has no detected operating systems. Or if you had previously installed Ubuntu, This computer has Ubuntu 22.04.1 LTS (Jammy Jellyfish) on it.. Select something else since we want to fiddle with partitions.

Here is the list of partitions,

Now select the partition you want to use for Ubuntu (the 130GB) and hit - to delete it. You'll see it converted to free space.

Reformat the freespace using + as Ext4 journaling file system with mount point /.

Do the same for Linux swap space, giving yourself about 10GB,

Finally, click on the Format ? box, then click on Install Now

Your last chance, so double check what Ubuntu wants to do!

Now continue the installation. Ubuntu asks you where you are located. Next, enter user name and password. You will be the superuser.

Now let the installation complete, remove the thumb drive and reboot into Ubuntu automatically. Ubuntu asks if you want to update; say yes.

Just for grins, open Terminal and run a manual updating and upgrade all software, then remove unneeded software,

sudo apt-get update sudo apt-get upgrade sudo apt-get autoremove
Two Display Screens Show Up Instead of One

The Mac comes up with two displays shown. Toggle one display to avoid showing one blank display when screen sharing.

Ubuntu Freezing at Boot Time

My computer was freezing upon bootup. It's a problem with NVIDIA drivers, and you can fix Ubuntu freezing by turning them off at bootup. I'll repeat the instructions here with minor changes for my system. Upon bootup, hit the ESCAPE key once. You might have to experiment to get the timing right. You'll go into a boot menu,

Hit the E key to go into edit mode and add the option nomodeset after the the quiet splash in the linux line,

Then save and reboot. To make changes permanent, not just for this boot, edit the grub configuration file,

sudo gedit /etc/default/grub
sudo update-grub2
Wireless Connection

Connect to your local Wireless node by clicking on the top right menu bar settings.

Select Wireless settings, and type in your Wireless Key and connect.

If you cannot connect to Wireless, you may need to install the Wireless driver. I found it by looking at Broadcom Linux Wireless Drivers Install using the line below and reboot after you install.

sudo apt install bcmwl-kernel-source
Mounting an Additional FAT Partition

I had an unused partition, so I launched the Disks application and formatted it as Extended FAT to be visible to Ubuntu. You might have to toggle the Right Arrow icon to mount it; it will say mounted at /media/sean/Backup

Here then is the final partition map,
Reading USB Drives Formatted in Extended FAT

To read a USB drive formatted in Extended FAT format, install the drivers.

sudo apt-get install exfat-utils exfat-fuse

Now you can format a USB drive as Ex FAT, plug it into your computer, and read it.