Well here’s my build script for ros2 jazzy
Enjoy
#Usual to ensure all upto date
sudo apt update
sudo apt upgrade
#I like vim! But please swap for favorite editor
sudo apt install vim
#Max out everything for swap!
#increase swap space (allocate more if needed): and zram compression
sudo apt install zram-tools
sudo dphys-swapfile swapoff
##Edit to increase swap as needed I used 8g on a 4g pi4
sudo vim /etc/dphys-swapfile
#AND SAME FOR I used 8g
sudo vim /sbin/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
sudo reboot now
#####################################################################################
#ROS2 on Pi raspbian is not available from repos, it must be built from source. as below
sudo apt install -y git colcon python3-rosdep2 vcstool wget python3-flake8-docstrings python3-pip python3-pytest-cov python3-flake8-blind-except python3-flake8-builtins python3-flake8-class-newline python3-flake8-comprehensions python3-flake8-deprecated python3-flake8-import-order python3-flake8-quotes python3-pytest-repeat python3-pytest-rerunfailures python3-vcstools libx11-dev libxrandr-dev libasio-dev libtinyxml2-dev
mkdir -p ~/ros2_jazzy/src
cd ~/ros2_jazzy # important NOT the src subdirectory created above, but this parent.
#This seems to be a very unreliable link, may need to run several times until no more “E”'s
##Otherwise can get missing libraries etc
vcs import --input https://raw.githubusercontent.com/ros2/ros2/jazzy/ros2.repos src
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo apt upgrade
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro jazzy -y --skip-keys “fastcdr rti-connext-dds-6.0.1 urdfdom_headers python3-vcstool”
#This takes about 8 hours on rpi4 4Gb. could even freeze due to memory problems, just rerun. Reduce/increase parallel workers if you have less/more memory than my 4GB
colcon build --symlink-install --parallel-workers 2
echo “source ~/ros2_jazzy/install/local_setup.bash” >> ~/.bashrc
source ~/.bashrc