开发者

Setting user environment variable and apply it to new processes

开发者 https://www.devze.com 2023-03-07 05:00 出处:网络
I\'m trying to set a global environment variable by adding it to the .bash_profile. What can I do (other than restarting), to apply this value globally, so 开发者_开发技巧that new processes (such as

I'm trying to set a global environment variable by adding it to the .bash_profile.

What can I do (other than restarting), to apply this value globally, so 开发者_开发技巧that new processes (such as Eclipse) can access this value?

Also, if my goal is adding a global environment variable, is writing it to the users' .bash_profile the best way, that doesn't require sudo?


If you add something like this to your .bash_profile:

export MY_TEST_VAR=1213222

You can then execute .bash_profile again in the current shell context

. .bash_profile

And your new processes will see this new enviroment variable


Rebooting is not necessary if it's not root's profile you modified. You just need to log off from your desktop, or close all the sessions where you want the environment refreshed.

The user's profile files is the best way to set user-specific variables.

If you want system-wide or group-wide settings, those are best left to root (for system-wide) or a restricted set of users.

You could for example implement a scheme like this: Have files like the following:

/usr/local/etc/my_group.profile 

readable by all users in mygroup but writable only by users of group mygroup_admins, and make the system-wide profile script source such files depending on the user's assigned groups. This gives you a bit of flexibility without having to hand out root privileges too much.

0

精彩评论

暂无评论...
验证码 换一张
取 消