How to set ANT_HOME on Ubuntu Desktop 12.04?

前端 未结 6 1615
时光取名叫无心
时光取名叫无心 2021-02-09 08:12

It looks like Ubuntu uses ~/.bashrc, ~/.bash_profile, ~/.pam_profile, /etc/environment, and /etc/profile in very

相关标签:
6条回答
  • 2021-02-09 08:43

    I'd prerer to put all environment variables to different file and source it from $HOME/.xsessionrc. .xsessionrc is simply a shell script which is executed after the new X session by login manager like gdm, kdm or so.

    0 讨论(0)
  • 2021-02-09 08:53

    For global settings, system-wide environment variables

    • Use /etc/environment
    • don't use /etc/profile, or /etc/bash.bashrc

    From this page :

    /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.

    Using /etc/profile is a very Unix-y way to go, but its functionality is greatly reduced under Ubuntu. It exists only to point to /etc/bash.bashrc and to collect entries from /etc/profile.d .

    On my system, the only interesting entry entry in profile.d is /etc/profile.d/bash_completion.sh .

    For local or per-user settings

    A previous version of the Ubuntu page recommended ~/.pam_environment , but the page currently suggests that if that doesn't work, you should use

    • ~/.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 or ~./bash_login - If one of these exists, bash executes it instead of "~/.profile" when bash is started as a login shell. Bash will prefer ~/.bash_profile to ~/.bash_login. [...] These files won't influence a graphical session by default."

    • ~/.bashrc - "... may be the easiest place to set variables".

    0 讨论(0)
  • 2021-02-09 08:54

    BEST way to set environment variables GLOBALY

    Step 1 :
    Set all variables in /etc/environment like this

    JAVA_HOME=/usr/lib/jvm/java-6-sun
    ANT_HOME=/usr/....<path to ant home>
    set path="/usr/bin:<path2>:$JAVA_HOME/bin:$ANT_HOME/bin"
    

    Step 2 :
    Add this line at the end of ~/.bashrc of each user

    source /etc/environment
    

    Step 3 :
    Execute the following command to make the changes.

    source ~/.bashrc
    



    Hope it helps..!!

    0 讨论(0)
  • 2021-02-09 08:57

    First, open bash file with following code.

    xxx@xxx-desktop:~$ sudo gedit /etc/bash.bashrc

    Then, Insert Java home as path to JDK location and ANT home as path ANT location as mentioned below at the end of bash file. I entered path for locations according to my machine.

      export ANT_HOME=/usr/share/ant
     export JAVA_HOME=/usr/lib/jvm/java-6-sun
     set path=$path $ANT_HOME/bin
    

    Eventually, save and close the file. If you configured correctly, the terminal must show following note with the command “ant –version”.

          xxx@xxx-desktop:~$ ant -version
    

    Apache Ant version 1.7.1 compiled on November 10 2008 It means configuration is Ok.

    0 讨论(0)
  • 2021-02-09 09:04

    To read the variable from java, use System.getenv().get("ANT_HOME"). Read more about it here.

    As for where to set it, I prefer using ~/.bashrc, unless you're going to run your program from other users, or with sudo. Then you should use /etc/environment

    0 讨论(0)
  • 2021-02-09 09:06

    Firstly, it's standard practice to omit the trailing slash when setting env variables on *nix. (You have a trailing slash at the end of yours). So you should write:

    export ANT_HOME=/opt/apache/ant/1.8.4/apache-ant-1.8.4

    ... and not:

    export ANT_HOME=/opt/apache/ant/1.8.4/apache-ant-1.8.4/

    ~/.bashrc, ~/.bash_profile are good if you only care about your user account and you use the bash shell. For setting an environment variable, it doesn't really make much difference which of these you use. .bashrc would reset it every time you opened a new shell, whereas .bash_profile would reset it every time you logged-in.

    The files in /etc would set it for all users on your system (but it could be overridden locally). If you're going to have different users building and you want them all to have the same environment varilables, then /etc/profile would be a good place to put it.

    0 讨论(0)
提交回复
热议问题