ROS2 and Apple Silicon

A short documentation on how I got ROS2 (Foxy) running on my Apple Silicon (M1)

Screenshot from the console output

I started with the binary (x86) version from here . For the installation prerequisites I avoided to go the classical python installation way, because the base installation more or less is read only on the Apple Silicons. Due to that I skipped the following steps

brew install python@3.8
brew link --force python@3.8

Instead I installed Anaconda via the official version from here. After installation all Anaconda programs can found here /opt/anaconda3/. Now start the Anaconda Navigator

/opt/anaconda3/bin/anaconda-navigator

The program somehow looks like the following screenshot.

Screenshot of Anaconda 3

Below “Environments” create a new environment e.g., named “ros2“. I Propose to use a Python version below 3.8 e.g., 3.7.1. My library setup:

Note: Especially the “matplotlib” und “grapviz” Python libraries are hard to install in Apple Silicon without Anaconda. Many thanks to the Anaconda community for doing the hard work in advance.

Now install the home-brew package manager (short “brew“) as described here. Afterwards proceed with the following lines as of the ROS2 installation guide.

brew install asio tinyxml2
brew install tinyxml eigen pcre poco
brew install opencv
brew install openssl
echo "export OPENSSL_ROOT_DIR=$(brew --prefix openssl)" >> ~/.bashrc
brew install qt freetype assimp
brew install console_bridge
brew install log4cxx spdlog
brew install cunit

Now comes the tricky part. It is important to understand that Apple hardened the MacOS with the Apple Silicon OS releases. This includes that the usual (I call it the “Linux”) directly schema is not longer applied e.g., /usr/local/ not contains programs and libraries, if not from x86 architecture. Due to that we have to install “brew” for x86 architecture. For doing so, we require the “Rosetta 2“. Rosetta allows to run x86 stuff on Apple Silicon (ARM).

/usr/sbin/softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once the installation is finished we are good to run x86 programs e.g., by adding the command prefix of “arch -x86_64“. In our case the install of the following libraries:

arch -x86_64 /usr/local/Homebrew/bin/brew install tinyxml
arch -x86_64 /usr/local/Homebrew/bin/brew install tinyxml2
arch -x86_64 /usr/local/Homebrew/bin/brew install openssl

Now we have to make the library available to the x86 ROS2.

cp /usr/local/Cellar/tinyxml2/9.0.0/lib/libtinyxml2.dylib <where ever you unzipped the ROS2 stuff>/ros2_foxy/ros2-osx/opt/yaml_cpp_vendor/lib/libtinyxml2.8.dylib

cp /usr/local/Cellar/openssl\@3/3.0.0_1/lib/libssl.dylib <where ever you unzipped the ROS2 stuff>/ros2_foxy/ros2-osx/opt/yaml_cpp_vendor/lib/libssl.1.1.dylib 

cp /usr/local/Cellar/openssl\@3/3.0.0_1/lib/libcrypto.dylib <where ever you unzipped the ROS2 stuff>/ros2_foxy/ros2-osx/opt/rviz_ogre_vendor/lib/libcrypto.1.1.dylib

So, we are close to the goal. In a next step we just have to open a terminal, activate our Anaconda environment and source ROS2.

conda activate ros2
bash
. <where ever you unzipped the ROS2 stuff>/ros2_foxy/ros2-osx/setup.bash

While running e.g., the “ros2” command you will receive a failure like “/usr/local/bin/python3: bad interpreter: No such file or directory“. To fix this, we just have the adapt the shell script interpreter line from

#!/usr/local/bin/python3

to

#!/opt/anaconda3/envs/ros2/bin/python3

And now we are done 🙂 Enjoy

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *