Skip to content

Path / environment variables, GNOME and Wayland: The definitive guide!

Hello everyone!

I would like to share my experiences trying to set my environment variables.
I just wanted to include ~/bin in $PATH. I thought it would be easy. Boy, was I ever wrong.

Let's start with some use cases.

  • Terminal. Usually you want to set your variables to use in this little application.
  • Other applications. For example, file-roller can extract exotic packages if it can find a suitable binary which can open it. It searches that binary in PATH. Edit: This includes the ALT+F2 run application shortcut, you need to have the app in your PATH before being able to run it this way.
  • "Open in Terminal". This useful feature of nautilus has caused me the most troubles. I will go back to this in a moment.

So, where can you edit your variables? Wiki gives us a great summary. Let me recap (replace bash with your favourite shell):

  • .profile Affects the terminal and all the other applications. Great. But for some reason, it does not work in "Open in Terminal". The terminal opened by nautilus has a different PATH variable than the regular ones. Maybe a bug?
  • .bashrc Works beautifully in both regular and nautilus terminals, but unfortunately the rest of the applications don't read this file. In addition, when you run another shell in a shell, it is read again, then you get duplicate ~/bins.
  • .pam_environment A great concept, but it is riddled with bugs. I must admit that I did not test it with other applications, but I can tell you, for some reason, this setting does not affect the regular terminal. Open in Terminal terminals has their variables set, not once, but twice! Apparently each time pam thing is run, ~/bin is appended. It is run twice in boot, so it is appended twice.

So this was for your usual Xorg setup. As I have been using Wayland in GDM for a long time now, and it is mostly stable, I decided to migrate my whole system to it.
.bashrc and .pam_environment behave the same. However, .profile (or the other profile files) are not read at all. I guess this is a bug with GNOME Wayland implementation.

Tables are fun:

Xorg Regular terminal Other applications / ALT+F2 "Open in Terminal"
.profile + + -
.bashrc + - +
.pam_environment - + +
Wayland Regular terminal Other applications / ALT+F2 "Open in Terminal"
.profile - - -
.bashrc + - +
.pam_environment - + +

After days trying to figure this out, I have decided to use .bashrc, even though it still feels a bit awkward. As this is pure personal experience and I did not read any implementation code at all, I did not want to put this in wiki. Please correct me if I missed anything, and maybe after the corrections this could be wiki-worthty! Thanks.

Edited 15 Jul 2015. We only hold this version.

2 points6 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
2 · 100% up
Kind
Text
ID
3dd783

11 comments

This is very inaccurate. You're missing knowledge about how environment variables work so you've interpreted your observations incorrectly. The key is that environment variables are inherited by child processes.

Only pam reads .pam_environment and then the environment it sets up is inherited by everything in the session. It's not buggy, you're just doing something wrong like overwriting the environment variables it sets later on. It also doesn't support shell-like variable expansion, etc. since it corresponds to /etc/environment rather than the pam_env.conf file. The .profile file (and .zprofile / .bash_profile for zsh/bash alone) is similarly only read by the login shell. Depending on how your session was started, there may not have been a proper top-level login shell which is the case for most display managers.

The .bashrc file is only read by non-login interactive Bash shells (which is why .bash_profile typically sources it). It's not for environment variables that are supposed to be set outside of an interactive shell. Export environment variables at the top of the session and be done with it. If you start sessions by logging in to a shell at a virtual terminal, that means a shell profile file. If you use a display manager, you'll have to use a method supported by it like .xprofile (depends on the display manager).

3 points
unknown author3 hidden

Deleted before we saved it.

-1 points

It's not GNOME's fault. It works for everyone else. Log in via a virtual terminal and start GNOME from there (either in Wayland or X11). It will inherit the environment and everything will be fine. If you're using a display manager, then you need to configure the display manager to export environment variables. That will vary based on whatever you've chosen to use. The .pam_environment file will always work though, since it doesn't need a login shell to run.

You may have configured the terminal to start a login shell (which is a bad idea) and I have no idea what your configuration looks like. It's likely that you've created various problems both by creating certain files (causing others to be ignored) and in the configuration within those files. Make a fresh user without any configuration files and see what happens there.

3 points

There's also ~/.xprofile

This is the place where you want to set per session variables. They'll be inherited by the whole session.

I can't test now, but that might possibly work with wayland too.

3 points
unknown author1 hidden

Deleted before we saved it.

1 points

not read at all

in what contextes?? it's read for sure with sddm, kdm (and afaik gdm lightdm)

1 points

None of this has anything at all to do with GNOME or Wayland.

What do you mean by "Other applications"? Nothing should be reading these files except for the shell (bash, zsh, csh, ...). Some are read when you first log in, others are read on the start of every shell instance.

This is a better link for bash: https://wiki.archlinux.org/index.php/Bash#Configuration_files

3 points
unknown author

Deleted before we saved it.

1 points
unknown author

Deleted before we saved it.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.