FedoraForum.org - Fedora Support Forums and Community
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2011
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to set environment variables permenently?

    How to set JAVA_HOME environment variables permanently such that it will not have to be set each time it has to be used

  2. #2
    Join Date
    Jun 2004
    Location
    Maryland, US
    Posts
    15,385
    Mentioned
    186 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    Quote Originally Posted by vefoda
    How to set JAVA_HOME environment variables permanently such that it will not have to be set each time it has to be used
    In your home directory, edit .bashrc to add this line

    export JAVA_HOME=/usr/java/latest
    or substitute whatever your JAVA_HOME is where I put /usr/java/latest.

    Any future bash shell launched will have that JAVA_HOME

  3. #3
    Join Date
    Mar 2011
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    How to edit .bashrc to add the line
    export JAVA_HOME=/usr/java/latest

  4. #4
    Join Date
    Jul 2006
    Location
    Montana
    Posts
    733
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    Quote Originally Posted by vefoda
    How to edit .bashrc to add the line
    You can also add that to .bash_profile (might be a better choice).

    Use any editor and add that line at the bottom.

    Code:
    gedit ~/.bashrc
    you can use nano, vim, emacs ....
    If it is not broken, tweak it... If you break Fedora you get to keep both pieces :p

  5. #5
    Join Date
    Nov 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    Rather than putting it in your home directory .bashrc, I would put it into /etc/bashrc That way the variable will be available for all users (root included).

  6. #6
    Join Date
    Jul 2009
    Location
    England, UK
    Posts
    969
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    Quote Originally Posted by Les62
    Rather than putting it in your home directory .bashrc, I would put it into /etc/bashrc That way the variable will be available for all users (root included).
    I believe the "approved" way of doing this for the whole system is to create a new file in /etc/profile.d/ rather than editing /etc/bashrc directly. (If you edit /etc/bashrc and bash is updated, you might get your edits overwritten, or you might not get the file updated.)

    So: run
    Code:
    su -c 'gedit /etc/profile.d/my-java-environment.sh'
    enter the line listed above by vefonda, save and exit.

    Changes to your own profile or the system profile will only affect new shells, so to see the effect you can just close the current terminal window, and open a new one (or log out and in again).

  7. #7
    Join Date
    Apr 2016
    Location
    United States
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to set environment variables permenently?

    Quote Originally Posted by marriedto51
    I believe the "approved" way of doing this for the whole system is to create a new file in /etc/profile.d/ rather than editing /etc/bashrc directly. (If you edit /etc/bashrc and bash is updated, you might get your edits overwritten, or you might not get the file updated.)

    So: run
    Code:
    su -c 'gedit /etc/profile.d/my-java-environment.sh'
    enter the line listed above by vefonda, save and exit.

    Changes to your own profile or the system profile will only affect new shells, so to see the effect you can just close the current terminal window, and open a new one (or log out and in again).
    Please be careful if you take this course of action, I tried this and apparently made an error. My laptop wouldn't login and only recognized basic bash commands, if this happens boot fedora with text only, login to root user and use 'command -p rm <path-to-file>' to erase it.

  8. #8
    Join Date
    Dec 2013
    Location
    United Kingdom
    Posts
    7,133
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)

    Re: How to set environment variables permenently?

    Please be even more careful following advice in old forum threads from 2011. If you need assistance with Java issues with the current version of Fedora please open a new thread.

Similar Threads

  1. how to set environment variables?
    By Seedrick in forum Using Fedora
    Replies: 3
    Last Post: 23rd May 2010, 01:47 PM
  2. Environment Variables
    By nightmarcus in forum Using Fedora
    Replies: 5
    Last Post: 20th January 2009, 12:31 PM
  3. Environment Variables
    By Curtor in forum Using Fedora
    Replies: 4
    Last Post: 14th February 2008, 09:01 PM
  4. environment variables?
    By hari_mj23 in forum Using Fedora
    Replies: 9
    Last Post: 3rd April 2006, 07:03 AM
  5. Environment variables
    By Flatron in forum Using Fedora
    Replies: 7
    Last Post: 28th January 2006, 03:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •