I've installed oracle JDK-8 on ubuntu 14.04 manually. but whenever I want to install a package that needs jdk8, apt-get tries to install jdk 8 again. my country is restricted so oracle server won't allow me to download jdk8.
$java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
and the results of apt-get are:
download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)
with this error, apt-get won't finish the installation.
oracle-java8-installer is not able to download file. So downlaod it manually from Oracle site and put into folder /var/cache/oracle-jdk8-installer/. And try to install oracle-java8-installer again. This solved the problem for me.
Step by step:
Check what file oracle-java8-installer is not able to download. You can see it in installation log. Let's suppose it's jdk-8u111-linux-x64.tar.gz
Google it jdk-8u111-linux-x64.tar.gz and you'll find exact page on Oracle site where to download it from. For our example it's http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Download jdk-8u111-linux-x64.tar.gz file and put in into folder /var/cache/oracle-jdk8-installer/.
And try to install oracle-jdk8-installer again: sudo apt-get install oracle-java8-installer Installation should finish successfully.
Try this,
First update the apt-get repos
$ sudo apt-get update
Add the java 8 repo to apt-get
$ sudo add-apt-repository ppa:webupd8team/java
Again update the apt-get repo
$ sudo apt-get update
Finally install java 8
$ sudo apt-get install oracle-java8-installer
References:
Ubuntu 16.04
Ubuntu 18.04
the first step:
sudo apt-get remove oracle-java8-installer
to clean up the failure installation of java8 perviously.
the second step:
sudo apt-get install oracle-java8-installer
to reinstall Java8
I suspect you've installed Oracle JDK8 using the archive, extracting to your own folder. It's probably the case that Ubuntu doesn't know that you've installed Java as the system Java and so is raising the error.
To be honest, I'm not sure how you go about installing it for system wide use but this page may provide some pointers. Installing Open JDK might be the better option, but an option is also given here, and this answer might also help.
One of the possible reasons and solution could be, that the version of the java package is updated with the possible vulnerability patch fix, and that needs to be updated in the PPA. I faced this when installing on ubuntu 16.04.
If the specific download error is that java download link is 404, than mostly
this solution will work.
Please remember to update the versions accordingly.
This worked for me:
First, go to below path:
cd /var/lib/dpkg/info
Run all 4 sed commands:
sudo sed -i 's|JAVA_VERSION=8u161|JAVA_VERSION=8u172|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="6dbc56a0e3310b69e91bb64db63a485bd7b6a8083f08e48047276380a0e2021e"|SHA256SUM_TGZ="28a00b9400b6913563553e09e8024c286b506d8523334c93ddec6c9ec7e9d346"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_161|J_DIR=jdk1.8.0_172|' oracle-java8-installer.*
Second:
sudo apt-get install oracle-java8-installer
If OpenJDK also OK for you, try to use sdkman for installing all java staff) It's a very cool tool.
I am trying to install webstorm, but when I try to run the *.sh file it gives me error of not having java environment available.
So I tried to look into the official documentation
But the steps to install the jdk didn't worked. I tried to locate java folder, but couldn't locate this directory /usr/bin/java
Please guide me how I can install webstorm now?
Java generally installs in /usr/lib/jvm/java-[major version]-openjdk-[arch]. Install a package such as openjdk-7-jdk and check in that location.
If you already have java installed, running which java will tell you the path of the java executable.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I haven't tried with java-8. Then:
sudo update-alternatives --java
And set auto-mode or java-7 (You might try with java-8)
First check the about java version
java -version
if its not returning you need to check your installed jdk
go to
cd /usr/lib/jvm
if you are finding something which start with java_XXXX
it means this is the only your jdk, and you can set JAVA_HOME as well path till bin folder by using export
I had a similar problem, during installation of eclipse (openjdk-7-jdk was required). I used
> sudo apt-get update
> sudo apt-get install ...
and it worked.
You should just install a JRE (to allow Java execution programs) and not a JDK (to develop Java programs).
No need a JDK to allow Webstorm to lauch.
On ubuntu : apt-get install default-jre
Have a nice day :)
David
I am trying to install Jenkins on ubuntu 11.04
I have installed Oracle Java
$:~$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)
$:~$ javac -version
javac 1.8.0_05
$:~$
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/jdk1.8.0_05/bin:/usr/lib/hadoop/hadoop-1.2.0/bin/:/usr/lib/pig/pig-0.12.0/bin:/usr/lib/hive/hive-0.11.0/bin:/usr/lib/hbase/hbase-0.94.8/bin
$:~$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.8.0_05
When I try to install, I have some dependency issues..
$ sudo apt-get install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
jenkins : Depends: daemon but it is not installable
Depends: default-jre-headless but it is not installable or
java-runtime-headless but it is not installable
E: Broken packages
to work install Jenkins they request Java versions greater than 1.8.0_1.
I got hte same error and I updated java to below version
java -version
java version "1.8.0_121"
Now jenkins installing without errors
Below link worked for 14.04 (hope it works for 11.04 too)
Install Java version in ubuntu
Try this:
sudo apt-get update
sudo apt-get remove default-jre default-jdk
sudo apt-get update
sudo apt-get install default-jre default-jdk
More about java on Ubuntu:
https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
Steps to install jenkins and view in browser with IP:-
sudo apt update
sudo apt search jdk --to search jdk
sudo install openjdk-8-jre
sudo install openjdk-8-jre-headless
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
add below line in the file /etc/apt/sources.list:
sudo nano /etc/apt/sources.list
OR
sudo vi /etc/apt/sources.list
Add this below link at the end of editing document.
deb https://pkg.jenkins.io/debian binary/
Update your local package index
sudo apt-get update
Install jenkins now
sudo apt install jenkins
start jenkins service
sudo systemctl start jenkins
Enable the jenkins service
sudo systemctl enable jenkins
Now jenkins installed in your system. If are following these steps
you are good to go. heat localhost:8080 in the browser. because jenkins works on
8080 by default. you can change it's port to others.
Now if are using google cloud then there is one more step.
Firewall rule details (Add firewall rule to enable ip and tcp 8080 port)
That's that now if you open in browser http://<your-ip>:8080 jenkins will open and ask you
to view the password which give location on the ui.
For more detail please visit
https://www.jenkins.io/
Your installation of Java is likely the Oracle zip / tgz drop. By using it, the package manager (dpkg / apt in this case) is unaware it is installed.
Install the packaged java for the package manager to "know" that the right java is isntalled, or install the zip / tgz drop of jenkins.
In short, if you want managed Jenkins, use the managed Java, and if you don't want it to be managed (sometimes that's a good option if you don't want it to be upgraded), don't use the managed Jenkins or Java. (Keep in mind that unmanaged means you get none of the bug fixes until you manually update, but it also means you get no surprises until you manually update).
Seems like you should run
sudo apt-get update
sudo apt-get upgrade
And try again.
Anyway, Jenkins users quite frecuently complain about the installer not working.
Your life will be easier if you do it manually. It is quite easy and you have complete instructions all around the web: http://clavadetscher.dyndns.org/wiki/en/Install_and_upgrade_Jenkins_CI_Server_on_Ubuntu_12.04_and_Tomcat6
note: tomcat7 (if you are tempted) has given me some headaches with Jenkins. I always end up installing tomcat6.
Ended up solving this by running the following command:
sudo add-apt-repository universe
Pre-made script for install Jenkins and it will also print the access code to the console for the first login as well.
You should be able to copy and paste
cd ~/
git clone https://github.com/120GBSSD/jenkins-install-xenial.git
chmod +x ~/jenkins-install-xenial/Ubuntu:16.04-Jenkins.sh
./Ubuntu:16.04-Jenkins.sh
Note: This is an old question and the answers reflect the world as it was then. Modern Ubuntu distributions have OpenJDK available which can be installed with
sudo apt install default-jdk
I am trying to install the Java Development Kit (JDK) on Ubuntu Linux distribution, but I am unable to install it.
What are the steps to install it on Ubuntu?
Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,
How to install Open JDK (Java developement kit) in Ubuntu (Linux)?
Open Terminal from Application Dash or press Ctrl+Alt+T
Update repository:
sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier
sudo apt update
Optional: To search available distributions of openjdk, use the following command:
apt search openjdk
Install the appropriate version with the following command:
sudo apt install openjdk-8-jdk
sudo apt install openjdk-8-source #this is optional, the jdk source code
For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
(Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)
For PATH (Environment Variable) type command as shown below, in Terminal:
export PATH=$PATH:$JAVA_HOME/bin
To check your installation:
java -version
The following used to work before the Oracle Java license changes in early 2019.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
The PPA is discontinued, until the author finds a workaround for the license issues.
You can install Oracle's JDK 1.7 fairly easily too; as an example this is how to install JDK 1.7.0_13;
Download the JDK from Oracle's site. The download to the newest version is always linked from http://java.oracle.com.
As root, do;
cd /usr/local
tar xzf <the file you just downloaded>
As your normal user, add or change these two lines in your ~/.profile to point to the installation;
export JAVA_HOME=/usr/local/jdk1.7.0_13
export PATH=$PATH:$JAVA_HOME/bin
If it's an update, you may also want to remove the old java installation directory in /usr/local.
Log out and in again (or do . ~/.profile), and everything should just work.
The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will, so I'd mostly consider it if you're running programs that require it.
In case you have already downloaded the ZIP file follow these steps.
Run the following command to unzip your file.
tar -xvf ~/Downloads/jdk-7u3-linux-i586.tar.gz
sudo mkdir -p /usr/lib/jvm/jdk1.7.0
sudo mv jdk1.7.0_03/* /usr/lib/jvm/jdk1.7.0/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
After installation is complete, set environment variables as follows.
Edit the system path in file /etc/profile:
sudo gedit /etc/profile
Add the following lines at the end.
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
Source: http://javaandme.com/
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
If you want to install the latest JDK 1.8, use the webupd8team PPA.
Add the repository in your system:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
You can now install Oracle Java 8 using the following command:
sudo apt-get install oracle-java8-installer
This ppa repository also provides a package to set environment variables automatically. Just type:
sudo apt-get install oracle-java8-set-default
OpenJDK is OK for the most cases, but Oracle JDK can be required for some bank client applications (my case) - I can't use OpenJDK.
I'm surprised that I don't see any answer with the default method (repository without external PPAs) in Ubuntu 12.10+ for Oracle's JDK - I will try to describe it.
Install JavaPackage:
sudo apt-get install java-package
Download Oracle JDK from Oracle downloads page
Make a Debian package from the downloaded .tar.gz archive:
make-jpkg jdk-YOUR_VERSION-linux-PLATFORM.tar.gz
This command will produce a .deb package.
Install the package in your favourite way (for example, sudo dpkg -i oracle-java8-jdk_8u40_amd64.deb)
It's the officially supported way from Debian developers for installing Oracle JDK, and I suppose it's very simple.
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
Installing Java 8 on Ubuntu
First you need to add webupd8team Java PPA repository in your system and install Oracle Java 8 using following set of commands.
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
Verify Installed Java Version
After successfully installing Oracle Java using the above steps, verify the installed version using the following command.
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
###Configuring the Java environment
In Webupd8 ppa repository also providing a package to set environment variables, Install this package using following command.
$ sudo apt-get install oracle-java8-set-default
Reference
Simply run:
sudo apt-get install default-jdk
Wiki from Ubuntu website:
For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
For Ubuntu 10.10, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
Installed in ubuntu 18.04
My workaround was,
$ sudo apt update
Install OpenJDK 8:
$ sudo apt install openjdk-8-jdk
Verify the Java installation by running the following command which will print the Java version:
$ java -version
The output should look like this:
Output:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Using a PPA (Obsolete)
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
You can use WebUpd8 PPA (this will download the required files from Oracle and install JDK 8):
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Are PPA's safe to add to my system and what are some “red flags” to watch out for?
Also ensure your JAVA_HOME variable has been set to:
/usr/lib/jvm/java-8-oracle
Manual install
The tar.gz provided by Oracle don't have an actual installation process. You just extract those files to a location you want and add them to your path. So the process is the following:
Download a .tar.gz from Oracle (here I will be using jdk-8u20-linux-x64.tar.gz);
Extract it to somewhere;
Move the extracted folder to /usr/lib/jvm. This is not required but it is the place where Java runtime software is installed
sudo mv /path/to/jdk1.8.0_20 /usr/lib/jvm/oracle_jdk8
Create a file /etc/profile.d/oraclejdk.sh with the following content (adapt the paths to reflect the path where you stored your JDK):
export J2SDKDIR=/usr/lib/jvm/oracle_jdk8
export J2REDIR=/usr/lib/jvm/oracle_jdk8/jre
export PATH=$PATH:/usr/lib/jvm/oracle_jdk8/bin:/usr/lib/jvm/oracle_jdk8/db/bin:/usr/lib/jvm/oracle_jdk8/jre/bin
export JAVA_HOME=/usr/lib/jvm/oracle_jdk8
export DERBY_HOME=/usr/lib/jvm/oracle_jdk8/db
Done! Those paths will only be recognized after you logout or restart, so if you want to use them right away run source /etc/profile.d/oraclejdk.sh.
In Ubuntu 18.04, We can install java like a normal package without using an external repository
Just run this command
sudo apt install openjdk-8-jdk
You can use the sudo apt-get install default-jdk terminal command to install the default JDK version.
Before installing Java, type the sudo apt-get update terminal command and then type the install terminal command. You can get more information from here.
Have a look at OpenJDK. It is the standard JVM implementation on Linux.
The best is to install default Java until a specific Java version is not required.
Before this, execute java -version to check if Java is not already installed.
sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk
That is everything that is needed to install Java.
I recommend JavaPackage.
It's very simple. You just need to follow the instructions to create a .deb package from the Oracle tar.gz file.
You can install via apt-get:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java11-installer
After, do not forget to check the version:
java -version
sun-java6-jdk is a virtual package provided by oracle-java8-installer or oracle-java7-installer or oracle-java7-installer.
sudo apt-get install oracle-java8-installer
will give you sun-java6-jdk.
I have successfully installed JDK 10 on Ubuntu 18.04 LTS following this video.
I am copying the excerpt from the description of the video.
Just open the terminal and give these commands :
For Java Installation (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
For setting up environment variables (make java10 default)
sudo apt-get install oracle-java10-set-default
The same procedure can be followed on Ubuntu 16.04, Linux Mint, Debian and other related Linux systems to install JDK 10.
You can use SDKMan,
curl -s "https://get.sdkman.io" | bash
source "~/.sdkman/bin/sdkman-init.sh"
sdk install java
If you want to install Oracle JDK, you can use this automated script that does all the work for you.
There are detailed instructions how to use it on the author's blog.
Installing Oracle's Java JDK requires you to accept the Oracle license before the installation begins. This is only required once. If for some reason you need the installation to be automated, you can run the following commands to install without user interaction, useful for an automatic script for example.
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer
java -version
Try to use SDKMAN! package manager - https://sdkman.io/install
Now it's the easiest way to install many JVM-based SDKs, tools and frameworks on any Linux distribution.
Upon installation, run the following command to see all available Java distributions:
sdk list java
Select the distribution that you need and install it:
sdk install java <version>
Install the appropriate version of OpenJDK
JAVA_VERSION=8
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get -qq install -y openjdk-$JAVA_VERSION-jdk
Set Environment Variables in /etc/profile.d/jdk.sh
JAVA_HOME=/usr/lib/jvm/java-$JAVA_VERSION-openjdk-amd64
echo "export JAVA_HOME=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh
echo "export J2SDKDIR=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh
echo "export J2REDIR=$JAVA_HOME/jre" | sudo tee -a /etc/profile.d/jdk.sh
echo "export PATH=$PATH:$JAVA_HOME/bin:$J2REDIR/bin" | sudo tee -a /etc/profile.d/jdk.sh
Check your installation
/bin/bash /etc/profile.d/jdk.sh
java -version
echo $JAVA_HOME
echo $J2REDIR
echo $PATH
Step 01: Download JDK
Download the JDK of required version from oracle official website :
[Oracle website to download JDK]: https://www.oracle.com/in/java/technologies/javase-downloads.html
e.i - jdk-11.0.12_linux-x64_bin.tar.gz
Step 02: Installation:
a) Extract the downloaded files using following command
sudo -tar -vzxf jdk-11.0.12_linux-x64_bin.tar.gz
b) Create a directory of name java inside usr/lib directory
mkdir java
c) Move the extracted jdk-11.0.12 directory inside the new created directory java
sudo mv jdk-11.0.12 /usr/lib/java
Step 03:
a) Execute following commands one by one
sudo update-alternative -install /usr/lib/java java /usr/lib/java/jdk-11.0.12/bin/java 1
sudo update-alternative -install /usr/lib/javac javac /usr/lib/java/jdk-11.0.12/bin/javac 1
Step 04: installation varification :
Verify the installation by using following commands
java --version
javac --version
You can use oraji. It can install/uninstall both JDK or JRE from oracle java (.tar.gz).
To install run sudo oraji '/path/to/the/jdk_or_jre_archive'
To uninstall run oraji -u and confirm the version number.
I had the same problem and none of the comments worked for me. Finally, I noticed that I disabled my updates. When I reactivate it, so sudo apt-get update worked correctly and the issue was solved.
(update in system settings> software and updates>updates tab
here I ticked two first option of important update and recommended updates).
Try this in case you do not want to install OpenJDK: JDK Source Installer for Ubuntu
In Ubuntu1604 I faced "No installation candidate error". Following below steps helped me install.
-sudo apt-get update
-sudo apt-get upgrade
-apt-get install software-properties-common
-sudo add-apt-repository ppa:webupd8team/java
-apt-get update
-sudo apt install oracle-java8-installer
Over Debian you can try
apt-get install default-jdk
According to Android Developer website, the following is the process to install Java 5 SDK
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
But, when I try to execute the last two commands I get an error -- the reason being the URL added to the repository by the first two commands is inaccessible.
I am using Ubuntu 11.04.
In that case, how do I execute Java 5 SDK?
If I install Java 5 SDK from http://java.sun.com, then I get error while *make*ing Android Sources due to the following reason
package com.sun.javadoc does not exist
Please suggest me a suitable way
You can try using the hardy repository. This works fine with Ubuntu 10.04 32bit.
$ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse"
$ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk
To confirm if successfully installed run.
$ sudo update-java-alternatives -l
To switch the Java version, run.
$ sudo update-java-alternatives
$ sudo update-java-alternatives -s java-1.5.0-sun
Then confirm if switched successfully, run.
$ java -version
If you install the Java 5 SDK from Oracle (downloading the .bin is my preferred method), when you are done, you will need to sudo edit your etc-alternatives configuration after the installation. You can tell which one your referencing by the command "which java" or "which javaw".
For Oracle JDK, it might be something like:
# update-alternatives --install "/usr/java/jdk1.6.0_26/java" "java" "/usr/java/default/bin/java" 3
# update-alternatives --install "/usr/java/jdk1.6.0_26/javac" "javac" "/usr/java/default/bin/javac" 3
If you don't use "update-alternatives", you can do it manually in /etc/alternatives/java, at minimum, you will need sudo access to update the java symbolic link so that the java in your path goes to the right location. Of course, there are other complications to this that you need to watch out for.
Because I like to be pure Oracle Java, I usually use "Oracle Solaris 11 Express" as my linux distro for java development.
11.04 is called natty narwhal; dapper is from a while ago. java 5 is really old too. you should be using java 6 or 7 now.