Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

ROS Installation

< Back to ROS Beginner tutorials
Before Getting Started
Installing ROS
Checking your ROS installation
Maintaining the installation
Recommendations
Additional
Alternatives
If you're using Ubuntu 16.04
Common Problems
Information

Before Getting Started

Before we get started, it's important that you understand a few things about this page. They are:

  • I've assumed that you're using a system running Ubuntu 18.04 (bionic beaver) for this tutorial and it's also assumed that you already know basics of Linux and Ubuntu.
  • All the codes used for these posts are present on the GitHub repository I've created for this.
  • Only the text written in code font can be executed on a terminal (you can copy and paste them). Any other text around it is for the explanation of that command.
  • In case you face any problems, check the Additional > Common Problems section and the Additional > Alternatives section
  • In case you're using an operating system other than Ubuntu 18.04, check the Additional > Alternatives section

Installing ROS

Official link

You need to have an active internet connection and must be running Ubuntu 18.04 (check Additional > Alternatives for other versions).

To install ROS perform the following steps

  1. Open the application Software and Updates and see that the options showing main, universe, restricted and multiverse are checked.
  2. Open a terminal window (Ctrl + Alt + T)
  3. Update everything on your system. Type in the following commands and press Enter after every command to execute it
    • sudo apt update
    • sudo apt upgrade -y
  4. Setup the sources so that your system can receive updates from packages.ros.org. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
      • You can check the Other Software section in Software and Updates application. A new line for packages.ros.org might have been added.
      • You can also verify the action by running the following command (and the output will have a link):
        • cat /etc/apt/sources.list.d/ros-latest.list
      • You could also do it using the GUI. Click the 'Add...' button enter "http://packages.ros.org/ros/ubuntu bionic main" and 'Add source'.
  5. Setup your keys for the keyserver. These will let you access the server and will let the server send things to you. Until now, you've only added it to the list, now you authenticate it. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
      • You must get an output telling that the public key for ROS builder has been imported
  6. Get the package index up to date so that it recognises the updates and packages available. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo apt update
      • You must have noticed that there are entries from "http://packages.ros.org/ros" this time. This means everything till now has gone fine and that you're ready for the main installation.
  7. Perform a desktop full install for ROS. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo apt install -y ros-melodic-desktop-full
      • This will fetch about 530MB of content, so it might take some time
  8. Now we need to setup rosdep. This is a tool that helps us install system dependencies for ROS. It is also essential for propoer functioning of some core components in ROS. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo rosdep init
      • This initialises the rosdep tool. It basically creates a list of essential things at a location. It can be seen in the output of the command
    • rosdep update
      • It updates the cache and reads sources
  9. Setup the ROS environment by running the setup script. Type in the following commands into the terminal and press Enter after every command to execute it
    • echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
      • This basically appends the line "source /opt/ros/melodic/setup.bash" in the ~/.bashrc file. You can alternatively open the file through a command like sudo nano ~/.bashrc, write "source /opt/ros/melodic/setup.bash" in the end and close it (Ctrl + X) and save it (Press 'Y' and then 'Enter').
      • By putting this line in the "~/.bashrc" file, ROS would be set up everytime you launch a new terminal
    • source ~/.bashrc
      • This basically refreshes the current terminal with the updated ".bashrc" file. You could alternatively close and reopen the terminal and it would have the same effect.
  10. Add dependencies for building packages. These are tools that help us handle workspaces in ROS. Type in the following commands into the terminal and press Enter after every command to execute it
    • sudo apt install -y python-rosinstall python-rosinstall-generator python-wstool build-essential
      • This installs the essential tools for python dependencies of ROS.

That's it ! You've successfully installed ROS on your system

Checking your ROS installation

To check if ROS has properly been installed or not, Type in the following commands into the terminal and press Enter after every command to execute it

  • printenv | grep ROS
    • This will show you environment variables with "ROS" in their name. Check the ROS_PACKAGE_PATH (it must be "/opt/ros/melodic/share") and ROS_DISTRO (it must be "melodic").

Maintaining the installation

Keep in mind these few critical points when using ROS

  1. ROS is set up whenever the command source /opt/ros/melodic/setup.bash is executed in a terminal. So if you want ROS to set up every time you open a terminal, it's a good idea to put this line in the "~/.bashrc" file.
    • In case you want to disable this automatic setup, you could comment out the line in "~/.bashrc" file. This could be useful when ROS interferes with other installed applications, OpenCV for instance (check the OpenCV point in Additional > Common Problems for more).
  2. If you have multiple versions or distributions of ROS installed, make sure at one instant, only one is sourced. You could comment out the rest in the "~/.bashrc" file.
  3. It's suggested that your create a section just for ROS in the "~/.bashrc" file. We'll later be adding a few more lines here and it's good to have it all in one place. You could just put a description comment before the setup line in the "~/.bashrc" file (comments begin with a '#').

This time onward, whenever you want to do anything ROS on a terminal, make sure that you have the installation sourced (either in the "~/.bashrc" file or do it manually every time).

Recommendations

  • I'd recommend that you install VSCode as well and use it for developing. The steps required to do the same are as follows:
    • Go to this website and download the VSCode for Debian (.deb extension for Ubuntu).
    • Double click on the .deb file downloaded and click on Install button for installing VSCode. Wait for the installing process to be finished.
    • Open a terminal and update the software. Type the following commands into the terminal and press Enter after every command to execute it
      • sudo apt update
      • sudo apt upgrade -y
      • sudo apt install pylint
      • pip install pylint
      • pip3 install pylint
    • Run the application
    • Go to extensions (it's the square like icon on the left panel) (Ctrl + Shift + X).
      • Search for "ROS" and install the extension developed by ajshort (it'll probably be the first result).
      • Search for "Code Spell Checker" and install the extension developed by Street Side Software (it'll probably be the first one).
      • Search for "Python" and install the extension developed by Microsoft.
      • Search for "C++" and install the extension developed by Microsoft.

Additional

Alternatives

If you're using Ubuntu 16.04

  • You must install ROS Kinetic instead of Melodic. Follow the same installation procedure as given, just make the following changes:
    • Replace "bionic" with "xenial" in step 4 if you're adding through GUI.
    • Replace "ros-melodic-desktop-full" with "ros-kinetic-desktop-full" in step 7.
    • Replace "melodic" with "kinetic" in step 9.
  • The outputs must contain "kinetic" instead of "melodic" when we're checking the installation
  • Keep in mind that the official support for this lasts only till April of 2021, whereas for ROS Melodic, it's till may 2023. More on this on the official install page.
  • Official installation guide.

Common Problems

Check if your internet connection is proper by loading some webpages, this is usually the root cause for most of the problems.

  • The keyserver command is giving an error
    • Instead of 'hkp://ha.pool.sks-keyservers.net:80' try 'hkp://pgp.mit.edu:80' or 'hkp://keyserver.ubuntu.com:80'
    • Try again at a later time
  • My OpenCV installation isn't working with ROS: This happens because ROS has it's own verison which shadows the original version
    • Comment out the line "source /opt/ros/melodic/setup.bash" in the "~/.bashrc" file and source ~/.bashrc. This must fix the problem.

Information

  • ROS runs officially on Ubuntu and Debian. It also has experimental versions on Arch linux, OS X (macOS, through homebrew), Windows and other operating systems. It is suggest that you use Ubuntu 18.04 for learning ROS.
  • You could check out the official installation page for more
  • Official documentation wiki page here. For ROS melodic, check here.


< Back to ROS Beginner tutorials
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse