Introduction
ROS has a really strict versioning. Each ROS version can only be run on the corresponding Ubuntu version or lower, there is no support for higher versions of Ubuntu.
There are many ways to resolve this like using a VM with a lower version of Ubuntu or using a docker container. This article details on the installation method of ROS Melodic in any Ubuntu version.
Here is a video reference that installs ROS2 through docker. You can refer this video and configure ROS1 yourself or you can continue following the article.
https://www.youtube.com/watch?v=qWuudNxFGOQ
Docker Installation
If you already have docker installed, you can skip this section. Here are a few references you can follow to install Docker.
ROS Melodic Installation
First step is to pull the ROS Melodic docker image from the official ROS repository.
docker pull osrf/ros:melodic-desktop
Running the docker container
docker run -it osrf/ros:melodic-desktop
- From the above steps you will be able to run the cli version of ROS1 melodic without any issues, but if you want to access the gui that comes with ros like rviz and gazebo, you would need to run the docker container differently.
As the command is pretty big, it is better to create a bash file that you can run with a single command.
Create a file with name of your choice and paste the following code in it.
# If not working, first do: sudo rm -rf /tmp/.docker.xauth
# It still not working, try running the script as root.
## Build the image first
### docker build -t r2_path_planning .
## then run this script
xhost local:root
XAUTH=/tmp/.docker.xauth
docker run -it \
--name=docker_container\
--env="DISPLAY=$DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--env="XAUTHORITY=$XAUTH" \
--volume="$XAUTH:$XAUTH" \
--net=host \
--privileged \
osrf/ros:melodic-desktop \
bash
echo "Done."
./docker_melodic_bash_file <container_name>
#docker_melodic_bash_file is the bash file name here
Restarting the Container
If you accidentally shut down your system while the container is running or stop the container, you can follow the following steps to restart the container.
docker restart <container_name>
docker exec -it <container_name> bash
Giving Docker sudo permission
There will be times when you would need docker to run as root. You can run the following command to do that.
sudo chmod 666 /var/run/docker.sock