ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Environment variables are not getting set

asked 2022-10-05 04:33:55 -0600

friendlycoder gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-10-06 03:15:26 -0600

friendlycoder gravatar image

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.

edit flag offensive delete link more
0

answered 2022-10-06 01:05:13 -0600

ravijoshi gravatar image

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.

edit flag offensive delete link more

Comments

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

gvdhoorn gravatar image gvdhoorn  ( 2022-10-06 02:03:41 -0600 )edit

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.

ravijoshi gravatar image ravijoshi  ( 2022-10-06 02:17:11 -0600 )edit

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

friendlycoder gravatar image friendlycoder  ( 2022-10-06 02:48:29 -0600 )edit

@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!

ravijoshi gravatar image ravijoshi  ( 2022-10-06 02:58:34 -0600 )edit

Question Tools

Stats

Asked: 2022-10-05 04:33:55 -0600

Seen: 1,009 times

Last updated: Oct 06 '22