Running ROS on Arch Linux (The Easy Way with Docker)

February 24th, 2018

Installing ROS on Arch is a pain in the rear. The fact that Arch is a rolling release distro makes it difficult to compile most of ROS dependencies. Even if you eventually manage to compile everything, you will find yourself running into all sorts of trouble compiling third party libraries, fixing problems between Python 3 and Python 2 and don’t even ask what happens when you do a system update.

Save yourself the trouble and use docker. You will be up and running in minutes and you will keep your system clean.

Step 1: Install Docker

sudo pacman -S docker && sudo usermod -aG docker $(whoami)

Step 2: Create ROS directory, catkin workspace (optional)

$ pwd
/home/piero
$ mkdir ros && cd ros
$ mkdir catkin_ws

Step 3: Add ROS .bashrc helpers

Put this in your ~/ros/.bashrc (note, not your ~/.bashrc !)

# ~/ros/.bashrc
ros-env(){
	source /opt/ros/kinetic/setup.bash
	source /ros/catkin_ws/devel/setup.bash
	export ROS_PACKAGE_PATH=/ros/catkin_ws/:/opt/ros/kinetic/share/
}
ros-env

This will take care of automatically setup your ROS environment when you access your docker container.

Step 4: Add home .bashrc helpers

There’s a lot of typing involved when using docker, so save yourself time and add these to your .bashrc file. Pay attention to the –device flags. In this example I’m making available the USB camera of my laptop at /dev/video0.

# ~/.bashrc
ros-start(){
docker run -it --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" -v /home/$(whoami)/ros:/ros --device /dev/video0 --device /dev/dri osrf/ros:kinetic-desktop-full bash -c "cp /ros/.bashrc /root/.bashrc && bash"
}

ros-connect(){
docker exec -ti $(docker ps -aq --filter ancestor=osrf/ros:kinetic-desktop-full --filter status=running) bash
}

ros-clean(){
docker rm $(docker ps -aq --filter ancestor=osrf/ros:kinetic-desktop-full --filter status=exited)
}

Step 5: Setup X Permissions

This is needed if you are running a GUI program within ROS.

# For the lazy and reckless, read http://wiki.ros.org/docker/Tutorials/GUI for The Safer Way
$ xhost +local:root

Step 6: Refresh

$ source ~/.bashrc

Step 7: Run it

To launch your ROS docker environment:

$ ros-start
root@abcdef$ rqt
( GUI appears )

To connect another shell to your ROS docker environment:

$ ros-connect

To cleanup old ROS containers

$ ros-clean

Make sure you’re familiar with how to use docker, and enjoy a clutter-free ROS running on Arch!