Robotics StackExchange | Archived questions

Environment variables are not getting set

Hi,

Even after running /opt/ros/foxy/setup.zsh, there are no shell environment variables with ROS in the name. I discovered this after debugging why CMake (run via colcon) could not find ament-related packages. This environment variable issue is currently my number one suspect, but I'm not getting closer to the cause.

$ source /opt/ros/foxy/setup.zsh                                                      
$ env|grep ROS                                                       
$

I have also tried this in bash, by running the corresponding setup.bash, with the same result. What could be the cause? Should these be set manually instead?

This is an Ubuntu 20.04.5 system on x86_64. I'm running ROS foxy.

Asked by friendlycoder on 2022-10-05 04:33:55 UTC

Comments

Answers

You are sourcing setup.zsh instead of setup.bash file. Please source the setup.bash file. Please see below:

ravi@dell:~$ source /opt/ros/foxy/setup.bash

Next, you can use env or printenv command as shown below:

ravi@dell~$ env | grep ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=foxy

ravi@dell~$ printenv | grep ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=foxy

Please note that the above commands are verified in Ubuntu 20.04.5 LTS. See below:

ravi@dell~$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:    20.04
Codename:   focal

Please check the documentation for more information.

Asked by ravijoshi on 2022-10-06 01:05:13 UTC

Comments

I believe the OP is trying to use the ZSH shell, which would indeed need the .zsh file.

Asked by gvdhoorn on 2022-10-06 02:03:41 UTC

Thank you very much. Based on the information reported, I assume that OP is using the default shell in Ubuntu 20.04.5 LTS, which is /bin/bash. Therefore using setup.zsh on bash shows the following error:

ravi@dell:~$ source /opt/ros/foxy/setup.zsh
bash: ${(%):-%N}: bad substitution
bash: cd: -q: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
bash: /setup.sh: No such file or directory

Let's wait for more information from OP.

Asked by ravijoshi on 2022-10-06 02:17:11 UTC

Hi, thanks a lot for the comments. I have now changed my shell to bash with chsh, rebooted, and tried the bash version of the setup script, but the results are unfortunately the same.

fdev@localhost:~$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"
fdev@localhost:~$ echo $SHELL
/usr/bin/bash
fdev@localhost:~$ ls /opt/ros/foxy/
bin    include  local_setup.bash  _local_setup_util.py  opt         setup.sh   share  tools
cmake  lib      local_setup.sh    local_setup.zsh       setup.bash  setup.zsh  src
fdev@localhost:~$ source /opt/ros/foxy/setup.bash
fdev@localhost:~$ env | grep ROS
fdev@localhost:~$ 

I also attempted uninstalling all ROS packages (with sudo apt --purge remove everything with ros in the name) and reinstalled them, with no change in the situation.

However, a workaround: putting those env variables listed by ravi into ~/.bashrc fixes it

Asked by friendlycoder on 2022-10-06 02:48:29 UTC

@friendlycoder: The echo $SHELL shows /bin/bash on my Ubuntu. Did you change these configurations? On the other hand, I am glad that you made it work. Nevertheless, let's try to figure out your case!

Asked by ravijoshi on 2022-10-06 02:58:34 UTC

Just in case anyone else stumbles upon this mystery, here's how I have finally solved it, by following the official documentation:

sudo apt install ros-foxy-desktop

So far, I have only been installing individual ROS packages that my project directly requires. However, setting these environment variables is the responsibility of some Ubuntu package that depends on ros-foxy-desktop (possibly ros-foxy-ros-base). When this package is not explicitly installed, the setup.bash script still gets created but it does not set ROS environment variables.

Asked by friendlycoder on 2022-10-06 03:15:26 UTC

Comments