Categories
big sur osx Rails

Homebrew on M1 is apparently all working – if you’re up to date

While checking how to install Ruby 3 on my new M1, I saw (also from brandur) that the full homebrew is now ready to roll!

However…..

This is really only true if you’re on the latest and greatest for all your projects. If, for example, you need a ruby <2.4 for something, then OpenSSL needs to be <1.1, and that’s not supported on arm, per https://github.com/rbenv/ruby-build/issues/1353#issuecomment-573414540. So I still set up the ibrew/abrew stuff, and then had to install old OpenSSL in the ibrew variant per above (or was it this? or this?). Btw I used the iTerm Rosetta.app variant to get things installed, and then tried to keep using it as I installed/built things, just to minimise variables to get to functional fast

ibrew install rbenv/tap/[email protected]

This only works on x86_64, so In order to get an old ruby installed, I needed double installs. In fact I needed to use x86_64 readline to get 2.4 & 2.5 installed.

# 2.3, but also works for 1.9.3-p551
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(/usr/local/bin/brew --prefix [email protected]) --with-readline-dir=/usr/local/opt/readline" arch -x86_64 rbenv install 2.3.3

# 2.4.10, 2.5.8
RUBY_CONFIGURE_OPTS="--with-readline-dir=/usr/local/opt/readline" arch -x86_64 rbenv install 2.4.10

Make sure you install rbenv yourself, not from brew, as you may need to pass some arch details

capybara-webkit still needs an old version of Qt, so you need to install the old 5.5 just like before. Make sure to follow all the steps! Including, adding it to your .profile, and make sure you run source ~/.profile before trying to compile again

pg will also probably freak out about not being able to get a clear line on which homebrew to use (especially as I installed the arm one as well), so you may need to specify

env ARCHFLAGS="-arch x86_64" gem install pg -v '0.21.0' -- --with-pg-config="$(ibrew --prefix postgresql-common)/bin/pg_config"

or

bundle config build.pg --with-pg-config="$(ibrew --prefix postgresql-common)/bin/pg_config"

libv8 and therubyracer continue to be pains in the arse:

brew install [email protected]
bundle config build.libv8 --with-system-v8
bundle config build.therubyracer --with-v8-dir=$(ibrew --prefix [email protected])
bundle install 
Categories
big sur osx postgresql

SHMMAX or SHMALL error on Big Sur

When upgrading to Big Sur with Homebrew, you may find errors on starting Postgres where there’s memory errors.

2021-03-30 17:26:07.203 AEST [47951] FATAL: could not create shared memory segment: Cannot allocate memory
2021-03-30 17:26:07.203 AEST [47951] DETAIL: Failed system call was shmget(key=5432001, size=56, 03600).
2021-03-30 17:26:07.203 AEST [47951] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMALL parameter. You might need to reconfigure the kernel with larger SHMALL.
The PostgreSQL documentation contains more information about shared memory configuration.
2021-03-30 17:26:07.204 AEST [47951] LOG: database system is shut down
stopped waiting
pg_ctl: could not start server

The short term (until reboot) solution lies here:

https://stackoverflow.com/questions/2017004/setting-shmmax-etc-values-on-mac-os-x-10-6-for-postgresql/10629164#10629164

Basically:

sudo sysctl -w kern.sysv.shmmax=12582912
sudo sysctl -w kern.sysv.shmall=12582912

But for a more permanent switch, since Catalina, editing /etc/sysctl.conf doesn’t work.

After further digging, the solution to this problem is to place a plist file into /Library/LaunchDaemons/ which runs and sets the shared memory parameters on boot. On Catalina this has to be preceded by disabling SIP, and remounting the / file system as writable, before installing the plist file.

https://developer.apple.com/forums/thread/669625

so, go to /Library/LaunchDaemons/, create a file (I called mine memory.plist, and make sure the owner is correct!), add the content below, and then run
sudo launchctl load memory.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>shmemsetup</string>
 <key>UserName</key>
 <string>root</string>
 <key>GroupName</key>
 <string>wheel</string>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/sbin/sysctl</string>
  <string>-w</string>
  <string>kern.sysv.shmmax=268435456</string>
  <string>kern.sysv.shmmni=128</string>
  <string>kern.sysv.shmseg=32</string>
  <string>kern.sysv.shmall=65536</string>
 </array>
 <key>KeepAlive</key>
 <false/>
 <key>RunAtLoad</key>
 <true/>
</dict>
</plist>

Once you’ve rebooted you can confirm by running

$ sysctl -A kern.sysv.shmall
kern.sysv.shmall: 65536

$ sysctl -A kern.sysv.shmmax
kern.sysv.shmmax: 268435456