Environment construction to automatically load setup.bash for each workspace moved by ROS

Overview

In this article, I will introduce how to use direnv easily and how to install it.

Motivation

If you use multiple workspaces properly in ROS, you need to do source devel / setup.bash for each workspace, which is awkward, so I was investigating whether it could be automated.

environment

Ubuntu 16.04 You can probably do it in other versions as well.

Method

There is something called direnv, and if you use this, it seems that setup.bash will be automatically loaded just by moving to each workspace root directory.

direnv installation method

I found a very helpful article (Let's use direnv), so basically it seems that you can build an environment if you set it according to this article. ..

go command not found

When I tried to install by referring to Use direnv, the error "go command not found" occurred.

Certainly, I don't remember introducing Go, so I think I need to add a new one.

Install Go

Here, I will introduce the method to install the latest version of go used in direnv with ʻapt install`.

You may not get the latest version of go with regular ʻapt-repository`

Go, which is a hot topic now, can be easily installed with ʻapt install`. ** But you have to be careful about the version in apt-repository **.

When go is installed as shown below without thinking about anything in my environment. .. ..

$ sudo apt update
$ sudo apt install golang-go

It was installed go 1.6. The latest version as of December 2019 is go 1.13, so a fairly old version has been installed. direnv requires at least a version of go 1.8 or later, so you cannot use direnv with this.

Updated ʻapt-repository to install the latest version of golang-go`

Therefore, in order to get the latest version, update ʻapt-repository` referring to here and install it again.

$ sudo add-apt-repository ppa:longsleep/golang-backports
$ sudo apt-get update
$ sudo apt-get install golang-go

Just in case, check the version

$ go version
go version go1.13.4 linux/amd64

And I was able to install the latest version safely.

Install direnv

I will also describe how to install direnv.

$ git clone https://github.com/direnv/direnv
$ cd direnv
$ sudo make install

Added the following to ~ / .bashrc

~/.bashrc


export EDITOR=vim  #You can specify your favorite editor. This time I use vim.
eval "$(direnv hook bash)"

How to use

For example, if there are catkin_ws and hoge_ws under / home / user /, execute the following in each directory.

//Move to workspace
$ cd ~/{ws_roos}

// .Creating an envrc/Edit
$ direnv edit .

Edit the created .envrc as follows.

~/{ws_root}/.envrc


source deve/setup.bash
##If you want output, add the following
# echo Auto sourcing source deve/setup.bash

Now just move to the workspace and it will automatically load setup.bash.

Summary

Even if you search for "ROS multiple workspace setup.bash automatic", you can't easily find the answer you want ...

reference

-Use direnv

Recommended Posts

Environment construction to automatically load setup.bash for each workspace moved by ROS
From environment construction to deployment for flask + Heroku with Docker
Python environment construction For Mac
Ansible environment construction For Mac
Python environment construction 2016 for those who aim to be data scientists
Switch the package to be installed for each environment with poetry
Spigot (Paper) Introduction to how to make a plug-in for 2020 # 01 (Environment construction)