LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   java installation (https://www.linuxquestions.org/questions/linux-newbie-8/java-installation-4175493819/)

jdepp 02-05-2014 11:19 AM

java installation
 
I tried to install java and was successful in downloading the rpm and installing jdk1.7.0_51 but the problem is I installed it to a created directory called java under the root. So now when I type java -version I get bash: java: command not found. I found some posts that advise adding the following:
export JAVA_HOME=mydirectory( which in this case is java)
Can someone advise what to do here and also if I download programs do I let it install in the default directory as root or is there an equivalent ProgramFiles folder?

MensaWater 02-05-2014 02:09 PM

Quote:

command not found
Means it didn't find the command. That means either it doesn't exist, it isn't accessible or it doesn't know where to look.

The most likely culprit being it doesn't know where to look.

You can fix that simply either:
1) Adding the directory where the java command is to your PATH variable.
2) Creating a symbolic link from where the java command is to a directory that is already in your PATH variable.
3) Typing the full path to where the binary is.

To see your PATH variable type "echo $PATH". You should see something like:
/bin:/usr/bin:/sbin:/usr/local/bin
Each of the items separated by the colons is a directory that will be searched when you type a command without a full path.

So if you the above PATH but the new install put your java binary in say /usr/lib/java1.7/bin/java you could either append the directory to your PATH:
export PATH=$PATH:/usr/lib/java1.7/bin
-OR-
Create the link:
ln -s /usr/lib/java1.7/bin/java /usr/local/bin/java

Also the above export would add it to your running PATH but would not add it for new sessions. To do that you'd have to modify the PATH= statement in the specific user's home directory file (e.g. .bashrc or .bash_profile) or if you want it for all users to the global profile such as /etc/profile or /etc/bashrc. (Note that after adding to a file a user has to either log out and login again or source the modified file for the change to take effect.)

John VV 02-05-2014 02:20 PM

What OS are you using , fedora,cent/RHEL already have OpenJDK already installed BY DEFAULT

Warning:
every rpm based system already has Openjdk installed!!!
If you want to replace that DEFAULT program with Oracles JAVA
you need to RESET "Alternatives"


Quote:

but the problem is I installed it to a created directory called java under the root.
DO NOT !!!!!!!!!! try to install java to a folder in the root home folder !!!!!!

do NOT run it as root !!!!!!!

for a rpm you use "yum" for Fedora/RHEL and "zypper" for opensuse
and use your package manager !!!( yum on centos)

for fedora
PLEASE READ and FALLOW the Mjmwired guide!
-- slightly old but still good
http://www.mjmwired.net/resources/mjm-fedora-f19.html

or
if you are using the current CentOS 6.5
openjdk is installed BY DEFAULT ( icetea)
http://wiki.centos.org/HowTos/JavaOn...961d93bcd10805


All times are GMT -5. The time now is 11:28 PM.