Reputation: 6864
I have downloaded oracle jdk tarball, and extracted it to /usr/lib/java/jdk1.8.0_172
directory.
I provided 755 permission to '/usr/lib/java/` directory recursively.
I then went ahead and changed my /etc/environment
script to be:
JAVA_HOME="/usr/lib/java/jdk1.8.0"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
Then typed:
source /etc/environment
and typed java -version
to confirm that it's recognised.
Once I logged off, everything is gone. And I cannot even find this after opening a new shell. I want this to work for any user, but cannot remember whether i have to add this to .bashrc
or some other file?
In other words, do i need to provide group access to this, or simply add the environment variables?
Upvotes: 0
Views: 25060
Reputation: 3554
What I usually do is, add a file to /etc/profile.d, along the lines of
#!/bin/sh
export JAVA_HOME=/usr/java
export PATH=$PATH:$JAVA_HOME/bin
This should be executed for every user on login.
One additional thing is, that I normally install the respective "current" java version under /usr/local, e.g. /usr/local/jdk1.8.0_172 and softlink this to /usr/java. That way I can easily upgrade and eventually switch back and forth without modifying and /etc-scripts. (Note: probably the best practices today recommend other directories than the ones I usually use ...)
Upvotes: 2
Reputation: 6864
I have done the following in one go and it worked.
1) Added source /etc/environment
to my /etc/profile
2) Typed source /etc/profile
3) exited the bash fully
4) Reopened the bash as sudo and typed java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
But I think this is also, because I provided 755 access to /usr/lib/java
recursively.
I had to go this extra mile because I am doing a proper "Sandboxed" development in those machines which have only intranet connectivity, and cannot see past that firewall :(
Otherwise, an sudo apt-get install openjdk-8-jdk-headless
would be my prefered option.
Upvotes: 0