# ROS setup tutorial

[ROS](http://www.ros.org/) (Robot Operating System) is a set of libraries and tools designed for robot applications. It mainly targets C++ and Python development and uses [catkin](http://wiki.ros.org/catkin) build system, which is based on CMake with Python scripts. ROS software [distributions](http://wiki.ros.org/ROS/Installation) are available for Linux, Windows, and also for macOS in experimental mode.

You can use CLion as an IDE for your ROS projects. This tutorial describes how to set up the workflow and gives an example of creating a ROS package and working with it in CLion. Note that this setup procedure has been tested on Ubuntu.

> **Tip:**
> There are also 3rd party plugins that you can use for ROS development in CLion: [ROS-Robot Operating System](https://plugins.jetbrains.com/plugin/11420-ros-robot-operating-system) and [Hatchery](https://github.com/duckietown/hatchery).
>
>
>
> Note: 3rd party plugins are not maintained or supported by the CLion team.

## Launch CLion in the sourced environment

CLion needs to be informed of the ROS-specific environment variables. These variables are retrieved in the current shell when you [source the workspace](http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment#Managing_Your_Environment) by running the following command from the workspace directory:

```CONSOLE
source ./devel/setup.bash
```

The simplest way to provide CLion with ROS environment variables is to launch the IDE from the same shell. After the workspace is sourced, you can type in the same terminal:

```CONSOLE
sh <PATH_TO_CLION>/bin/clion.sh
```

## Open a ROS project in CLion

After you have launched CLion in the sourced environment, do one of the following to open your ROS project:

* Click `File | Open` and select `CMakeLists.txt` in the `src` directory of your ROS workspace, then choose Open as Project.

* Click `File | New CMake Project from Sources` and select the `src` directory of the workspace to import the project from.

The CMake tool window will show the status of the project loading:

![successfully load cmake project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_cmakeload_success.png)

> **Note:**
> If you are using [catkin_tools](https://catkin-tools.readthedocs.io/en/latest/index.html), there is no top-level `CMakeLists.txt` for the whole workspace. In this case, you will need tp open each package as a separate project in CLion (choose `CMakeLists.txt` from the package directory). Feature request for catkin_tools support in CLion: [CPP-7438](https://youtrack.jetbrains.com/issue/CPP-7438).
>
>
>
> For more information about the difference between catkin build and catkin_make, refer to [Catkin_tools Migration Guide](https://catkin-tools.readthedocs.io/en/latest/migration.html)

## Set build paths to the catkin workspace

By default, CLion places build output in `cmake-build-debug` or `cmake-build-release` directory that is created automatically. For ROS development, it means that you will have two different builds in CLion and in the console where you run `catkin_make`.

To have a single build across the IDE and console, you need to set CLion build paths to the catkin workspace directories. For this, go to `File | Settings `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `⌘ Comma` (Xcode), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (ReSharper), `⌘ Comma` (ReSharper (macOS)), `Ctrl+Alt+S` (QtCreator), `⌘ Comma` (QtCreator (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) | Build, Execution, Deployment | CMake` and change two fields:

* In Build directory, set `<WORKSPACE_DIRECTORY>/build`.

* In CMake options, add `-DCATKIN_DEVEL_PREFIX:PATH=<WORKSPACE_DIRECTORY>/devel`.

## Work with launch files

You can [run](running-applications.html) and [debug](starting-the-debugger-session.html) ROS nodes as regular applications in CLion.

[Launch](http://wiki.ros.org/roslaunch/XML) files cannot be executed directly, but you can edit them with XML syntax highlighting and completion, and [attach the debugger](attach-to-process.html) to a running node.

Procedure: Attach the debugger to a running node

1. Run your `.launch` file from the command line. For example

```CONSOLE
roslaunch roscpp_tutorials talker_listener.launch
```

You can check the list of currently running nodes by the `rosnode list` command. In our example, the list will contain `talker` and `listener`:

![ros nodes list](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_nodelists.png)

2. Call `Run | Attach to Process` from the main menu or press `Ctrl+Alt+F5` (Windows), `⌥ ⇧ F5` (macOS), `⌥ ⇧ F5` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ F5` (macOS System Shortcuts), `Ctrl+Alt+5` (XWin), `Ctrl+Alt+5` (GNOME), `Ctrl+Alt+5` (KDE), `Ctrl+Alt+F5` (Emacs), `Ctrl+Alt+F5` (Sublime Text), `⌥ ⇧ F5` (Sublime Text (macOS)), `⌥ ⇧ F5` (Xcode), `Ctrl+Alt+P` (Visual Studio), `⌘ ⌥ P` (Visual Studio (macOS)), `Ctrl+Alt+F5` (ReSharper), `⌃ ⌥ F5` (ReSharper (macOS)), `Ctrl+Alt+F5` (QtCreator), `⌥ ⇧ F5` (QtCreator (macOS)), `Ctrl+Alt+F5` (NetBeans), `Ctrl+Alt+F5` (Eclipse), `⌥ ⇧ F5` (Eclipse (macOS)).

3. Connect to the desired node by its PID or name:

![attach to ros node](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_attachtonode.png)

## Example: create a basic ROS node, edit and run it in CLion

In this example, we will create a simple ROS package, edit the source code, and run the node from CLion. We will use ROS Melodic on Ubuntu 18.04 and the basic publisher node from the [Writing a Simple Publisher and Subscriber (C++)](http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29) tutorial available on the [ROS wiki](http://wiki.ros.org/ROS).

Procedure: Create a basic ROS package

1. Create and build a ROS workspace:

```SHELL
mkdir -p ros_workspace/src
cd ros_workspace
catkin_make
```

2. In the workspace, create a package called `my_package`:

```SHELL
cd src
catkin_create_pkg my_package roscpp rospy std_msgs
```

Procedure: Launch CLion

1. Source the workspace:

```CONSOLE
cd ../../../
source ./devel/setup.bash
```

2. And launch CLion in the same terminal:

```CONSOLE
sh /opt/clion-2018.2/bin/clion.sh
```

Procedure: Open the package as a project in CLion

* In CLion, go to File | Open in the main menu and select the `CMakeLists .txt` file located inside the package folder, and choose to open it as a project:

![open ros project](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_openprj.png)

Procedure: Add a source file and edit CMakeLists.txt

1. Add a new source file to the project: right-click `src` in the Project tree, select `New | C/C++ Source File` and call it `my_package.cpp`.

2. Copy the entire [talker.cpp](https://raw.githubusercontent.com/ros/ros_tutorials/kinetic-devel/roscpp_tutorials/talker/talker.cpp) file from the [Publisher and Subscriber](http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29) tutorial into `my_package.cpp`.

3. Add the newly created source to `CMakeLists.txt` and [link](http://wiki.ros.org/catkin/CMakeLists.txt#target_link_libraries) it against catkin libraries:

```CMAKE
add_executable(my_package src/my_package.cpp)
target_link_libraries(my_package ${catkin_LIBRARIES})
```

After that, [reload](reloading-project.html) the CMake project, and notice my_package in the list of Run/Debug configurations:

![add source to cmakelists and reload](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_addcpp_reload.png)

Procedure: Run a ROS node

1. Before running the node from CLion, open the ROS master in a new terminal:

```CONSOLE
roscore
```

2. In CLion, Run ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.execute.svg) the my_package configuration. Run tool window will show the node output:

![output of the running node](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_runnode.png)

3. In a separate terminal, check the currently active ROS topics.

If we print the messages from `chatter`, the output will be similar to what we can see in CLion:

![ros chatter node running](https://resources.jetbrains.com/help/img/idea/2026.2/cl_ros_chatter.png)

Now if we stop the application in CLion, the `rostopic echo /chatter` command will have no output.

## See also

### Getting Started

[Quick CMake tutorial](quick-cmake-tutorial.html)

### External Links

[ROS wiki](https://wiki.ros.org/)

