익명 22:15

Reload environment variables without relogin to desktop

Reload environment variables without relogin to desktop

I've found multiple ways to update environment variables to an Ubuntu system with a desktop environment, some common answers are:

  • /etc/environment
  • /etc/profile and /etc/profile.d/*.sh
  • $HOME/.profile
  • $HOME/.pam_environment

And well many also say $HOME/.bashrc which only applies to bash and so is really not correct.

It does not seem to be possible to update the environment via any of these means in a running system. If I open a new terminal tab, a new terminal window, close the terminal and reopen the entire application, or launch a completely different application, at no point does any of them seem to re-evaluate any of these files

Since I need to update the environment on a regular basis for development tools etc., and have multiple long running tasks (stuff that takes days or weeks to complete) that I don't want to terminate, this is not particularly convenient.

How do I get a running desktop environment to reload and apply updates to environment variables, so that I don't have to close everything I'm doing to get newly launched software (e.g. IDEs, Git GUI clients, etc.) to see the updated environment?

If it matters, I'm using XFCE4 for the desktop environment.



Top Answer/Comment:

You can use the source command to re-read the file in question, for example

source $HOME/.profile

It can be abbriavated to a dot like

. $HOME/.profile

But if you want to set some environment variables to use in application, it might be more feasable just to set them in a shell session and start the application from there, as muru mentioned in a comment. This would be something like

export LANG=fr_FR
/some/path/to/an/executable

You could also set an environment variable for one specific command

LANG=fr_FR /some/path/to/an/executable

If you use something like the above on a regular basis, you could write a short script that does the task, something like

#!/bin/bash
export LANG=fr_FR
/some/path/to/an/executable

Put the script somewhere in your $PATH, let's say /usr/local/bin with a name like for example start_important_application, and then you can use this command to start your app.

It may be possible to use something like LANG=fr_FR some_command in the Exec key of a custom starter file (those files that end with .desktop), but I haven't tested that.

상단 광고의 [X] 버튼을 누르면 내용이 보입니다