Installation (macOS)

Goal: Install the webots_ros2 package and run simulation examples on macOS.

Tutorial level: Advanced

Time: 10 minutes


The webots_ros2 package provides an interface between ROS 2 and Webots. It includes several sub-packages, including webots_ros2_driver, which allows you to start Webots and communicate with it. Other sub-packages are mainly examples that show multiple possible implementations using the interface. In this tutorial, you are going to install the package and learn how to run one of these examples.


It is recommended to understand basic ROS principles covered in the beginner Tutorials. In particular, Creating a workspace and Creating a package are useful prerequisites.

It is necessary to install Webots natively on the mac in order to use the webots_ros2 package in the virtual machine as explained below. You can follow the installation procedure or build it from sources.


On macOS, a solution based on UTM virtual machines provides an improved user experience with ROS 2 compared to native macOS installation, as it runs ROS in a Linux environment. However, Webots should be installed natively on macOS and it will be able to communicate with the ROS nodes running in the Virtual Machine (VM). This solution allows for native 3D hardware acceleration for Webots. The VM runs all the ROS part (including RViz) and connects to the host machine through TCP to start Webots. A shared folder allows the script to transfer the world and other resource files from the VM to macOS where Webots is running.

The following steps explain how to create the VM image with the installation of the webots_ros2 released package. It is also possible to install it from sources.

1 Create the VM image

Install UTM on your macOS machine. The link can be found on the official UTM website.

Download the .iso image of Ubuntu 22.04 for Humble and Rolling or Ubuntu 20.04 for Foxy. Be sure to download the image corresponding to your CPU architecture.

In the UTM software:

  • Create a new image and choose Virtualize option.

  • Select the ISO image you have downloaded in the Boot ISO Image field.

  • Leave all hardware settings at default (including hardware acceleration disabled).

  • In the Shared Directory window, select a folder that will be used by webots_ros2 to transfer all the Webots assets to the host. In this example, the selected folder is /Users/username/shared.

  • Leave all the remaining parameters as default.

  • Start the VM. Note that you can select another shared folder each time you start the VM.

  • During the first launch of the VM, install Ubuntu and choose a username for your account. In this example, the username is ubuntu.

  • Once Ubuntu is installed, close the VM, remove the iso image from the CD/DVD field and restart the VM.

2 Configure the VM

In this section, ROS 2 is installed in the VM and the shared folder is configured. The following instructions and commands are all run inside the VM.

  • Open a terminal in the started VM and install the ROS 2 distribution you need by following the instructions in Ubuntu (Debian packages):

  • Create a folder in the VM to use as a shared folder. In this example, the shared folder in the VM is /home/ubuntu/shared.

    mkdir /home/ubuntu/shared
  • To mount this folder to the host, execute the following command. Don’t forget to modify the path to the shared folder, if it is different in your case.

    sudo mount -t 9p -o trans=virtio share /home/ubuntu/shared -oversion=9p2000.L
  • To automatically mount this folder to the host when starting the VM, add the following line to /etc/fstab. Don’t forget to modify the path to the shared folder, if it is different in your case.

    share     /home/ubuntu/shared     9p      trans=virtio,version=9p2000.L,rw,_netdev,nofail 0       0
  • The environment variable WEBOTS_SHARED_FOLDER must always be set in order for the package to work properly in the VM. This variable specifies the location of the shared folder that is used to exchange data between the host machine and the virtual machine (VM) to the webots_ros2 package. The value to use for this variable should be in the format of <host shared folder>:<VM shared folder>, where <host shared folder> is the path to the shared folder on the host machine and <VM shared folder> is the path to the same shared folder on the VM.

    In this example:

    export WEBOTS_SHARED_FOLDER=/Users/username/shared:/home/ubuntu/shared

    You can add this command line to the ~/.bashrc file to automatically set this environment variable when starting a new terminal.

3 Install webots_ros2

You can either install webots_ros2 from the official released package, or install it from the latest up-to-date sources from Github.

Run the following command in the VM terminal.

sudo apt-get install ros-jazzy-webots-ros2

4 Launch the webots_ros2_universal_robot example

As mentioned in previous sections, the package uses the shared folder to communicate with Webots from the VM to the host. In order for Webots to be started on the host from the VM’s ROS package, a local TCP simulation server must be run.

The server can be downloaded here: Specify the Webots installation folder in WEBOTS_HOME environment variable (e.g. /Applications/ and run the server using the following commands in a new terminal on the host (not in the VM):

export WEBOTS_HOME=/Applications/

In the VM, open a terminal and execute the following commands to start a package:

First source the ROS 2 environment, if not done already.

source /opt/ros/jazzy/setup.bash

If installed from sources, source your ROS 2 workspace, if not done already.

cd ~/ros2_ws
source install/local_setup.bash

If not already set in ~/.bashrc, set WEBOTS_SHARED_FOLDER (see previous sections for details). Be sure to change the paths according to the location of your respective directories.

export WEBOTS_SHARED_FOLDER=/Users/username/shared:/home/ubuntu/shared

Use the ROS 2 launch command to start demo packages (e.g. webots_ros2_universal_robot).

ros2 launch webots_ros2_universal_robot

If Webots is closed or the ROS 2 process is interrupted, the local server will automatically wait for a new package launch and the shared folder will be cleaned for the next run.