What do you need, and when?
ROS2 consists of many libraries, all of which you will install while learning. When you get more advanced, you will put only the necessary parts where you need them. To start with you will need compilers, command-line tools, and simulators. For external systems, you will want to have only the finished nodes and the communication core of the system. In the early stages, you need to try some examples and see how to simulate a robot or even several robots in action. Those tools are only available in the desktop install.
How does ROS help?
The libraries in ROS are meant to give you many standard functions for robotic activities. It has libraries for sensor handling, motor control, and much more. The focus is on the communication between nodes, which is a core concept of each function in the ROS framework.
You have options!
You can install the ros-base package with your favorite package manager. The problem is that you may use many versions of the ROS system for different projects. To avoid this problem, use a container. You will end up installing in the same way, only inside the container. The point, in the end, is that the ROS system comes in several versions and they can only run on a certain distribution version. Here is a short table:
|Ubuntu Ver.||ROS2 ver.||ROS1 ver.|
There are more versions and more dependencies, see the list at the wiki on ros.org. The point is that you have to make sure your setup supports the ROS version. ROS also uses Python to a high degree, they are testing for Python 3 (and 2.7) so you can choose. There is also a docker image available if you are more comfortable with that. The image is named ros:foxy-ros-base-focal.
Depending on what you are working with, you may need a different amount of software, which is a second reason to use containers. As you see in the table, you may also need to choose ROS1 or ROS2. If you use both, it is a big risk that settings confuse things for your compilers and other tools. The end of life for ROS1 is 2025, so don’t start new big projects with it.
Many parts inside
The Robotics Operating System has many subsystems. You need to know which one is needed where, and when you should have it installed. As soon as you start installing, you run into the choice of how much you want to install. By default, you will use your package manager to install the entire distribution. This is called ros-desktop-full, you will have all that you may need. It also takes a lot of space on your drive.
The ROS Core makes it possible to compile your programs through the rclcpp and rclpy client libraries. These are the two that the ROS developers maintain. More clients exist for other languages. They use the API to create consistent behavior across platforms. Included at this level are also all the ways your robotic system will communicate.
The ros-base includes many tools for development but contains no GUI tools.
Contains all different pieces of the system, including many examples. It also gives you all the GUI tools, including simulators and ways to test communication between nodes. The only extra things you need will be special drivers and some extra implementations of i.e. the urdf parser.
Installing ROS Desktop
The simplest way to install the ROS desktop is to use apt for Ubuntu and other Debian based distributions. On other distributions, you need to build it yourself. When you do, the result is put in a single directory structure. This means you will need to initialize that environment by sourcing the setup file. Uninstall is to remove the directory structure and stop sourcing the setup file. The sourcing you will need to do with Debian packages also.
The ROS2 packages are available as their repository at their repository. To add that to your system, copy their key.
And then add their repositories.
http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main"
When that is done, you can update and install the libraries.
sudo apt install ros-foxy-desktop
With all this installed, you need to initialize the environment in the shell you are running.
Add this line to your .bashrc script, so all invocations of bash are ready for you to work. This is also where using a Linux container comes in handy. When you have several projects, using different versions, it is better to create a virtual machine only for ‘Foxy’ and another one for each you need.
While the basic installation is simple for ROS2, you need to be precise about what you want. If you stay with one distribution, you have no problems but start using many versions and you have complications.