How to install java 7 on mac in custom location? - java

I want to install java 7 on mac silently. I am unable to find any documentation/links on the same. Also I don't want it in /Library. Is it possible to install the same on any custom location. I am very new to mac any help is highly appreciated.

Just to make the steps from #HawkMage more explicit (and illustrate them working with JDK8):
Download the binary (eg, jdk-8u5-macosx-x64.dmg) from Oracle
Double click from Finder to mount the Volume. Ignore the window with the “JDK 8 Update x.pkg”
Use pkgutil to expand the contents of the package into a temporary directory:
$ pkgutil --expand /Volumes/JDK\ 8\ Update\ 05/JDK\ 8\ Update\ 05.pkg /tmp/jdkpkg
Then, change to that dir and use cpio to expand the Payload file:
$ cd /tmp/jdkpkg
$ cpio -i < ./jdk18005.pkg/Payload
Finally, move the Home dir to wherever you’d like your JAVA_HOME to live
$ mv Contents/Home /mytools/jdk-1.8.0_05

Unfortunately the "standard" Java that comes on OS X is packaged in a very non-standard way.
It is not as easy as linux, the DMG downloaded gives you a PKG file that if you run it just installs Java. This is not useful if you are trying to keep the standard Java that comes with OS X intact.
What I do is download the DMG file from Oracle and open it but instead of running the PKG I use pkgutil to extract the contents of the package. You will find a directory named jdk*.pkg and in it you will see a file named Payload. This is a GZipped CPIO file and you can extract it by cating it and piping it into cpio -zi. From this you will now have a directory named Contents and under it you will find a directory named Home. This "Home" directory is the what you would normially get with the Linux tar.gz Java download. You can copy it to wherever you want and put the bin directory in your path and set the JAVA_HOME to it and you are good to go.

Just like in Linux, you can pretty much install Java anywhere you like on a mac. You just need to make sure that you add the Java executable to the path or create a symbolic link of the java executable and put it in the /usr/bin/ directory so it can be executed anywhere.
To add Java to path:
1) Modify .bash_profile found in your home director.
2) Add this line: export PATH=/yourjavadir/bin:$PATH
3) Save and exit
4) Then do source .bash_profile to reload the file. You'll only need to do this one time.
To create a symbolic link:
ln -s /yourjavadir/java /usr/bin/java

I had the same issue and just managed to figure it out.
Download and unzip the Java binary in your custom directory. For eg -
/Users/myuser/Documents/jre1.8.0_25.jre
Update your .bash_profile with the following parameters
export JAVA_HOME=/Users/a514624/Documents/jre1.8.0_25.jre/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
Close the terminal window and open it again. Alternately, you could type the command 'source .bash_profile'.
After these steps, if you type java -version on the command prompt, you would see it reflecting the version which you were hoping to see -
$ java -version
java version "1.8.0_25" Java(TM) SE Runtime
Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM
(build 25.25-b02, mixed mode)
Unlink the existing Java softlink (would require root/elevated privileges)
root$ unlink /usr/bin/java
Create a symbolic link to the new Java installation
root$ ln -s /Users/myuser/Documents/jre1.8.0_25.jre/Contents/Home/bin/java /usr/bin/java
Thats it. Life is beautiful after this. Hope this helps!

If you just need JRE/Java Runtime Edition then previous answers arecorrect but if you need JRE and JDK (Java Development Kit) then simply go to below link and select the mac and run the dmg and it's much better and by far the easiest.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Related

Red Hat Linux Enterprise 5.7 remove Java

I need to uninstall Java jdk1.6.0.27 from RHEL 5.7 and then install another version jre-7u40-linux-x64.rpm.
The firs thing I did was to find out the current java version installed using the
java -version command and the output is "java version "1.6.0_27"".
After that I tried to check the previews version of java with the command:
rpm -qi jdk
The output is "package jdk is not installed"
After installing the package jre-7u40-linux-x64.rpm in the /usr/java directory there are two java packages.
The output of the ls command on /usr/java is:
default jdk1.6.0_27 jre1.7.0_40 jre-7u40-linux-x64.rpm latest.
when I run the command "alternatives --config java" the output is:
*+ 1 /usr/java/latest/bin/java
I am new to RHEL and I need some help to understand the situation.
To conclude I need some help to remove the previews jdk1.6.0.27 and to install jre1.7.0_40.
Thank you in advance for your help!
Best regards,
Claudio
First, find out your real java executable. Start with
which java
This is going to give you some response such as:
/usr/bin/java
Next, do
ls -l /usr/bin/java
(Or whatever it returned).
It will probably write something like:
/usr/bin/java -> /etc/alternatives/java
Do the same for whatever is pointed to by the arrow, until finally, when you do ls -l on it, there is no arrow.
Then, for that particular file, find out which rpm provides it by using
rpm -q -f <full path of the file you found>
It should tell you which package it belongs to, and then you can uninstall that.
However, if the rpm command returns The file ... is not owned by..., then your Java has not been installed using an rpm. It may have been installed manually by someone in the past.
This makes uninstalling it a lot more problematic.
If you haven't found your answer:
leave old java where it is, don't even bother with it
install new version with: rpm -ivh /root/jdk-7u40-linux-x64.rpm
deactivate old java
export new version
Deactivating old java (note entering hashtags before every line, manual installation required editing of profile, so edit it one more):
vi /etc/profile
#JAVA_HOME=/usr/java/jdk1.6.0_27
#export JAVA_HOME
#PATH=$JAVA_HOME/bin:$PATH
#export PATH
Exporting nev version (note adding new lines in profile followed after old entries):
export JAVA_HOME=/usr/java/latest
export JRE_HOME=$JAVA_HOME/jre
export J2RE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$J2RE_HOME/bin:$PATH
Check nev version with standard command for checking of installed sw.
Hope this suits your needs.
Just wondering: you're trying to prepare BFBOX for acceptance? Just courious! If you want more info please send me an email, ok?

Ubuntu now able to set java path

I have installed oracle jdk in /usr/lib/jvm/ and i have setted up path in etc/environment as
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
But still when i am running javac, I am getting following error. The program 'javac' can be found in the following packages:
* default-jdk
* ecj
* gcj-4.6-jdk
* gcj-4.7-jdk
* openjdk-7-jdk
* openjdk-6-jdk
It means javac is not installed or java path has not setted properly, however i am able to see javac,java,jps and other programs in my /usr/lib/jvm/jdk1.7.0_51. I have searched enough about it but still not able to get solution of this problem.
The file /etc/environment is not a file executed by the shell (like a shell script); you cannot use $SOMETHING references in this file. Variables are not substituted in this file. So,
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=$PATH:$JAVA_HOME/bin
the second line will not work like this. You have to put the exact path in.
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
PATH=...:/usr/lib/jvm/jdk1.7.0_51/bin
The javac binary (and probably other java binaries) is/are not in your user's $PATH environment variable. There are several ways you can address this:
Add /usr/lib/jvm/jdk1.7.0_51/bin to your user's $PATH
environment variable. You can do this by adding a line similar to
the following in your user's .bash_profile:
export PATH=${PATH}:/usr/lib/jvm/jdk1.7.0_51/bin
You'll have to restart your terminal session for it to take effect.
Create symbolic links to the java binaries from some directory
that's already part of your path (such as /usr/bin)
sudo ln -s /usr/lib/jvm/jdk1.7.0_51/bin/java /usr/bin/
sudo ln-s /usr/lib/jvm/jdk1.7.0_51/bin/javac /usr/bin/
BTW: There are several other java executables in /usr/lib/jvm/jdk1.7.0_51/bin. see the symlink commands for java and javac above. You should run similar command for any other executables you may want to use.
Use the fully qualified path directly on the command line:
$ /usr/lib/jvm/jdk1.7.0_51/bin/javac
https://help.ubuntu.com/community/Java
have you tried this page? Its where I go when I need Java info. You may not have the one you installed set as default.
Could it be that you did not refresh the shell after change in path variable?
if you echo $PATH are the changes present?

Unable to run threaded java jar file on Mac OS X 10.6.8 with Java 1.7.0.45 using pacifist

I have installed Java 1.7.0_45 on Mac OS X 10.6.8 using Pacifist [http://www.charlessoft.com/] however I am unable to run a jar file which I have downloaded. The jar file is a threaded application.
The error message I am getting is:
java -jar context.jar
2013-10-31 14:14:41.898 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement methodSignatureForSelector: -- trouble ahead
2013-10-31 14:14:41.900 java[330:a07] *** NSInvocation: warning: object 0x109356390 of class 'ThreadUtilities' does not implement doesNotRecognizeSelector: -- abort
Trace/BPT trap
Is there anyway I can run the jar. I have set the JAVA_HOME path properly and java -version is showing 1.7.0_45 as the version.
The same application works properly on Windows Java 1.7.0_45 and also on Linux Java 1.7.
The web search for the solution and the given keywords return very few results and none of them have any specific solution in it. I am new to mac so I am not fully able to understand the issue.
Alternatively, is there anyway I can run Java from folder in Mac like I can do in windows and Linux by just extracting the Java contents and changing the JAVA_HOME. If that is possible then I should be able to run my JAR.
I had kind of same problem while installing an application through jar file, my Java was not detected by the jar application installer,
Over here I see that one of the method is not accessible, could be a same problem. But I am not very sure of it.
make sure you have rt.jar in your JAVA_HOME/jre/lib/ folder
In case you don't have then you are required to have it through the process of creation of symbolic link.
In the command below replace your_java_version with proper version matching your requirement.
sudo mkdir -p /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib
Go into the directory:
cd /System/Library/Frameworks/JavaVM.framework/Versions/<your_java_version>/Home/jre/lib/
Create symbolic link :
sudo ln -s ../../../Classes/classes.jar rt.jar
Hope this solves your problem.
I get the exact same problem with MacOS 10.6.8 and JDK 7. In order to run the jar I had to use the System JRE which is 1.6.x (In my case I wanted to install Squirrel
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar >squirrel-sql-3.6-MACOSX-install.jar

run .jar file with "java" command Centos

I'm trying to run a .jar file on my centos box, but it says "java: command not found".
What's the best or easiest way to solve this? I was hoping for a yum command but not sure that that will exist for java?
Apparently some versions of CentOS doesn't come with a JVM installed due to some licensing restriction. See HowTo Install Java on CentOS 4 and CentOS 5 for instructions.
You can use such command to check if Java is available in your repository:
yum list | grep java
It should return something like that:
java-1.6.0-openjdk
java-1.6.0-sun
If such package exists you can install it using such command (run it as the root user):
yum install java-1.6.0-openjdk
Either the JRE is not installed or, more likely, its location is not included in your PATH environment variable. If the java executable is not in your PATH, you would need to use the full path & filename to execute it.
cd to the location of the jar file
C:\temp>java -jar sample.jar

java version in linux

# which java
/usr/bin/which: no java in (/usr/local/jdk/jdk1.5.0_10/bin/java:/usr/local/jdk/jdk1.5.0_10/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin)
I installed java in /usr/local/jdk/jdk1.5.0_10 but cannot run java -version
I get this
$ java -version
-bash: /usr/bin/java: No such file or directory
this is red hat linux
It's not in your path.
use
export PATH=$PATH:/usr/local/jdk/jdk1.5.0_10/bin
export JAVA_HOME=/usr/local/jdk/jdk1.5.0_10
Look at ~/.bash_profile for where to define this permanatly.
Can you do
ls /usr/local/jdk/jdk1.5.0_10/bin
And why is /usr/local/jdk/jdk1.5.0_10/bin/java in your path?
Must be in local path of java before running to see what version is installed. Use find / -name java (this will list anything with java on the server copy the path ). path should end with..../jre/bin/java
copy full path.
Open Java location of the path you copied above, remove java at the end you path then enter,
Enter command below:
./Java -Version

Categories