设置用户环境变量并将其应用到新进程
我试图通过将全局环境变量添加到 .bash_profile
来设置它。
我可以做什么(除了重新启动之外)来全局应用此值,以便新进程(例如 Eclipse)可以访问此值?
另外,如果我的目标是添加全局环境变量,那么将其写入用户的 .bash_profile
是不需要 sudo 的最佳方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将类似的内容添加到
.bash_profile
中:您可以在当前 shell 上下文中再次执行
.bash_profile
您的新进程将看到此内容新环境变量
If you add something like this to your
.bash_profile
:You can then execute
.bash_profile
again in the current shell contextAnd your new processes will see this new enviroment variable
如果您修改的不是
root
的配置文件,则无需重新启动。您只需从桌面注销,或关闭您想要刷新环境的所有会话。用户的配置文件是设置用户特定变量的最佳方式。
如果您想要系统范围或组范围的设置,最好将这些设置留给
root
(对于系统范围)或一组受限的用户。例如,您可以实现这样的方案:拥有如下文件:
mygroup
中的所有用户都可读,但只能由mygroup_admins
组中的用户写入,并使系统-宽配置文件脚本根据用户分配的组来获取此类文件。这为您提供了一定的灵活性,而无需授予太多的root
权限。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:
readable by all users in
mygroup
but writable only by users of groupmygroup_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 outroot
privileges too much.