You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Humble.

Windows (source)

This guide is about how to set up a development environment for ROS 2 on Windows.

Prerequisites

First follow the steps for Installing Prerequisites on the Binary Installation page.

Stop and return here when you reach the “Downloading ROS 2” section.

Language support

Make sure you have a locale which supports UTF-8. For example, for a Chinese-language Windows 10 installation, you may need to install an English language pack.

Additional prerequisites

When building from source you’ll need a few additional prerequisites installed.

Install additional prerequisites from Chocolatey

First install git:

choco install -y git

You will need to append the Git cmd folder C:\Program Files\Git\cmd to the PATH (you can do this by clicking the Windows icon, typing “Environment Variables”, then clicking on “Edit the system environment variables”. In the resulting dialog, click “Environment Variables”, the click “Path” on the bottom pane, then click “Edit” and add the path).

Install developer tools

Now we are ready to install some our tools that we use to help in developing ROS 2.

Let’s start with vcstool:

pip install -U vcstool

You can test it out by just running vcs (you should be able to do this in the same cmd prompt).

Next, install colcon:

pip install -U colcon-common-extensions

You can test it out by just running colcon (you should be able to do this in the same cmd prompt).

Also, you should install curl:

choco install -y curl

Install dependencies

Next install the latest version of setuptools and pip:

python -m pip install -U setuptools pip

Then you can continue installing other Python dependencies:

pip install -U catkin_pkg cryptography EmPy ifcfg lark-parser lxml numpy pyparsing pyyaml

Next install testing tools like pytest and others:

pip install -U pytest pytest-mock coverage mock

Next install linters and checkers like flake8 and others:

pip install -U flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mypy==0.761 pep8 pydocstyle

Next install cppcheck:

choco install -y cppcheck

Next install xmllint:

Install Qt5

Download the 5.12.X offline installer from Qt’s website. Run the installer. Make sure to select the MSVC 2017 64-bit component under the Qt -> Qt 5.12.12 tree.

Finally, in an administrator cmd.exe window set these environment variables. The commands below assume you installed it to the default location of C:\Qt.

setx /m Qt5_DIR C:\Qt\Qt5.12.12\5.12.12\msvc2017_64
setx /m QT_QPA_PLATFORM_PLUGIN_PATH C:\Qt\Qt5.12.12\5.12.12\msvc2017_64\plugins\platforms

Note

This path might change based on the installed MSVC version, the directory Qt was installed to, and the version of Qt installed.

Get the ROS 2 code

Now that we have the development tools we can get the ROS 2 source code.

First setup a development folder, for example C:\dev\ros2_foxy:

md \dev\ros2_foxy\src
cd \dev\ros2_foxy

Get the ros2.repos file which defines the repositories to clone from:

vcs import --input https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos src

Install additional DDS implementations (optional)

If you would like to use another DDS or RTPS vendor besides the default, you can find instructions here.

Build the ROS 2 code

To build ROS 2 you will need a Visual Studio Command Prompt (“x64 Native Tools Command Prompt for VS 2019”) running as Administrator.

Fast RTPS is bundled with the ROS 2 source and will always be built unless you put an AMENT_IGNORE file in the src\eProsima folder.

To build the \dev\ros2_foxy folder tree:

colcon build --merge-install

Note

We’re using --merge-install here to avoid a PATH variable that is too long at the end of the build. If you’re adapting these instructions to build a smaller workspace then you might be able to use the default behavior which is isolated install, i.e. where each package is installed to a different folder.

Note

If you are doing a debug build use python_d path\to\colcon_executable build --cmake-args -DCMAKE_BUILD_TYPE=Debug. See Extra stuff for debug mode for more info on running Python code in debug builds on Windows.

Environment setup

Start a command shell and source the ROS 2 setup file to set up the workspace:

call C:\dev\ros2_foxy\install\local_setup.bat

This will automatically set up the environment for any DDS vendors that support was built for.

It is normal that the previous command, if nothing else went wrong, outputs “The system cannot find the path specified.” exactly once.

Test and run

Note that the first time you run any executable you will have to allow access to the network through a Windows Firewall popup.

You can run the tests using this command:

colcon test --merge-install

Note

--merge-install should only be used if it was also used in the build step.

Afterwards you can get a summary of the tests using this command:

colcon test-result

To run the examples, first open a clean new cmd.exe and set up the workspace by sourcing the local_setup.bat file. Then, run a C++ talker:

call install\local_setup.bat
ros2 run demo_nodes_cpp talker

In a separate shell you can do the same, but instead run a Python listener:

call install\local_setup.bat
ros2 run demo_nodes_py listener

You should see the talker saying that it’s Publishing messages and the listener saying I heard those messages. This verifies both the C++ and Python APIs are working properly. Hooray!

Note

It is not recommended to build in the same cmd prompt that you’ve sourced the local_setup.bat.

Next steps after installing

Continue with the tutorials and demos to configure your environment, create your own workspace and packages, and learn ROS 2 core concepts.

Additional RMW implementations (optional)

The default middleware that ROS 2 uses is Fast-RTPS, but the middleware (RMW) can be replaced at runtime. See the guide on how to work with multiple RMWs.

Extra stuff for Debug mode

If you want to be able to run all the tests in Debug mode, you’ll need to install a few more things:

  • To be able to extract the Python source tarball, you can use PeaZip:

choco install -y peazip
  • You’ll also need SVN, since some of the Python source-build dependencies are checked out via SVN:

choco install -y svn hg
  • You’ll need to quit and restart the command prompt after installing the above.

  • Get and extract the Python 3.8.3 source from the tgz:

  • Now, build the Python source in debug mode from a Visual Studio command prompt:

cd C:\dev\Python-3.8.3\PCbuild
get_externals.bat
build.bat -p x64 -d
  • Finally, copy the build products into the Python38 installation directories, next to the Release-mode Python executable and DLL’s:

cd C:\dev\Python-3.8.3\PCbuild\amd64
copy python_d.exe C:\Python38 /Y
copy python38_d.dll C:\Python38 /Y
copy python3_d.dll C:\Python38 /Y
copy python38_d.lib C:\Python38\libs /Y
copy python3_d.lib C:\Python38\libs /Y
copy sqlite3_d.dll C:\Python38\DLLs /Y
for %I in (*_d.pyd) do copy %I C:\Python38\DLLs /Y
  • Now, from a fresh command prompt, make sure that python_d works:

python_d -c "import _ctypes ; import coverage"
  • Once you have verified the operation of python_d, it is necessary to reinstall a few dependencies with the debug-enabled libraries:

python_d -m pip install --force-reinstall https://github.com/ros2/ros2/releases/download/numpy-archives/numpy-1.18.4-cp38-cp38d-win_amd64.whl
python_d -m pip install --force-reinstall https://github.com/ros2/ros2/releases/download/lxml-archives/lxml-4.5.1-cp38-cp38d-win_amd64.whl
  • To verify the installation of these dependencies:

python_d -c "from lxml import etree ; import numpy"
  • When you wish to return to building release binaries, it is necessary to uninstall the debug variants and use the release variants:

python -m pip uninstall numpy lxml
python -m pip install numpy lxml
  • To create executables python scripts(.exe), python_d should be used to invoke colcon, along with the corresponding CMake build type. If you installed colcon using pip, the path to the colcon executable can be found with pip show colcon-core.

python_d path\to\colcon_executable build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=Debug
  • Hooray, you’re done!

Stay up to date

See Maintain source checkout to periodically refresh your source installation.

Troubleshooting

Troubleshooting techniques can be found here.

Uninstall

  1. If you installed your workspace with colcon as instructed above, “uninstalling” could be just a matter of opening a new terminal and not sourcing the workspace’s setup file. This way, your environment will behave as though there is no Foxy install on your system.

  2. If you’re also trying to free up space, you can delete the entire workspace directory with:

    rmdir /s /q \ros2_foxy