RHEL7: How to set up an environment variable.

Share this link

Presentation

Let’s suppose you need to assign “/usr/lib/jvm/java-1.8.0” to the JAVA_HOME environment variable.

You can need to set up an environment variable in at least three different cases:

  • for a simple user (we will take the centos user as an exemple),
  • for the root user,
  • for all the users (root included).

Simple User Configuration

Connect as the centos user (or any user that you chose except root). By default you should be at the root of the home directory. If it’s not the case, type cd.

Edit the .bash_profile file and paste the following line at the end of the file:

export JAVA_HOME=”/usr/lib/jvm/java-1.8.0″

Root User Configuration

Connect as the root user. By default you should be under /root. If it’s not the case, type cd.

Edit the .bash_profile file and paste the following line at the end of the file:

export JAVA_HOME=”/usr/lib/jvm/java-1.8.0″

All Users Configuration

Connect as the root user. Create a file with any name finishing by .sh in the /etc/profile.d directory (here we will use javaenv.sh).

Paste the following line into the file:

export JAVA_HOME=”/usr/lib/jvm/java-1.8.0″

Set the correct access rights on the file:

# chmod 0755 /etc/profile.d/javaenv.sh

Note: This is required otherwise only the root user would get the environment variable assigned.

Source: StackExchange.com

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5.00 out of 5)
Loading...

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 10 minutes.
Archive and compress the content of the /opt directory (create files if none exists).
Uncompress and unarchive the resulting file in /root

RHCE7: Task of the day

Allowed time: 10 minutes.
Change the SSH process configuration to only listen on the 443 port.

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...