gpt4 book ai didi

java - 如何在 Ubuntu Desktop 12.04 上设置 ANT_HOME?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:41:04 30 4
gpt4 key购买 nike

看起来 Ubuntu 使用 ~/.bashrc, ~/.bash_profile, ~/.pam_profile, /etc/environment/etc/profile 的方式非常相似。我希望能够向其中一个(哪个是合适的)添加配置以将 ANT_HOME 设置为我的 Ant 安装根目录的绝对路径(恰好是 /opt/apache/ant/1.8.4/apache-ant-1.8.4/)。这个变量需要像任何普通的 env var 一样被“尊重”,我可以在其中打开一个终端并随时 echo 它。如果我可以将其设置为让 Java 在运行时从 System.getProperty("") 调用中读取它,那就太好了。

  • 我使用哪个文件?
  • 如何实际设置它才能满足我的上述要求?

在此先感谢您的帮助或指点!

最佳答案

对于全局设置,系统范围的环境变量

  • 使用/etc/environment
  • 不要使用/etc/profile,或者/etc/bash.bashrc

来自 this页面:

/etc/environment [...] is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.

使用 /etc/profile 是一种非常 Unix-y 的方式,但在 Ubuntu 下它的功能大大减少了。它的存在只是为了指向 /etc/bash.bashrc 并从 /etc/profile.d 收集条目。

在我的系统上,profile.d 中唯一有趣的条目是 /etc/profile.d/bash_completion.sh

对于本地或每用户设置

以前版本的 Ubuntu 页面推荐 ~/.pam_environment ,但该页面当前建议如果那不起作用,则应使用

  • ~/.profile - This is probably the best file for placing environment variable assignments in, since it gets executed automatically by the DisplayManager during the startup process desktop session as well as by the login shell when one logs-in from the textual console.

  • ~/.bash_profile~./bash_login - 如果其中之一存在,当 bash 存在时,bash 将执行它而不是“~/.profile”作为登录 shell 启动。 Bash 将更喜欢 ~/.bash_profile 而不是 ~/.bash_login。 [...] 默认情况下,这些文件不会影响图形 session 。”

  • ~/.bashrc - “...可能是设置变量最简单的地方”。

关于java - 如何在 Ubuntu Desktop 12.04 上设置 ANT_HOME?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12224804/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com