Installing Java (openjre-6) on Ubuntu Server without internet access

Print Friendly, PDF & Email

If you administer a lot of Ubuntu machines in many different locations, odds are you’ve been in the situation where you need to install a package,
and in this case more specifically openjdk-6-jre, withou access to the internet or any apt repository.

The simplest way to do this is to manually install using a .deb package (syntax: sudo dpkg -i package_name.deb ), although that will mean you will have to meet some strict dependencies, which in itself can become a nightmare to figure out.

There is another way and it’s simpler than you think – although some functionality might not be available. If you simply want to be able to execute ‘java’ with some parameters, for example generating reports from your web application, then read on..

Step 1:
Download the ‘self extracting archive’ version of Java from the Java website. (It will be in .bin file format). Yes, you will need internet for this, but you can download it on any machine and just copy it over to your Ubuntu Server using ssh/sftp/scp/etc.

Step 2:
Copy the downloaded file (in my case jre-6u30-linux-x64.bin) to your Ubuntu Server. I normally copy it over using FileZilla to /var/tmp.

Step 3:
Do the following on your Ubuntu Server to extract the Java Files. You can do it anywhere, but I chose /usr/share/java because it makes sense.

#become 'root', so you don't have to type 'sudo' the whole time
sudo bash
 
#create a 'java' directory
mkdir /usr/share/java
chmod 755 /usr/share/java
 
#go into newly created directory
cd /usr/share/java
 
#move the .bin file which you copied over in Step 2 to the newly created directory (you can also copy it directly to this directory from the start)
mv /var/tmp/jre-6u30-linux-x64.bin .
 
#chage the file to allow execution
chmod a+x jre-6u30-linux-x64.bin 
 
#execute the file
./jre-6u30-linux-x64.bin
 
#This should generate a lot of output about 'deflating','moving', 'creating', etc

Java is now on your server.

Step 4:
To allow it to execute from anywhere, you need to create 2 soft-links to the /usr/bin directory

#remember to replace the '/usr/share/java/' with whichever directory you decided to use as your java location
 ln -s /usr/share/java/jre1.6.0_30/bin/java /usr/bin/java
 ln -s /usr/share/java/jre1.6.0_30/bin/javac /usr/bin/javac

You should now be able to execute ‘java’ from the command line. You can test it to make sure as follows:

root@techedemic:/usr/share# java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
root@techedemic:/usr/share#

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.