tags:

views:

2307

answers:

4

I'm trying to start working with Java, but so far haven't been able to get it on my machine properly. I'd really like to be able to compile from command line. After following the instructions here with no errors I can't compile with javac. Here's what I have so far:

When I enter:

$ java -version

I get:

java version "1.6.0_16"  
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)  
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)

When I run:

$ sudo apt-get install sun-java6-jdk

I get:

~$ sudo apt-get install sun-java6-jdk  
Reading package lists... Done  
Building dependency tree          
Reading state information... Done  
Suggested packages:  
  sun-java6-demo sun-java6-doc sun-java6-source  
The following NEW packages will be installed:  
  sun-java6-jdk  
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.  
Need to get 17.4MB of archives.  
After this operation, 55.7MB of additional disk space will be used.  
WARNING: The following packages cannot be authenticated!  
  sun-java6-jdk  
Install these packages without verification [y/N]? y  
Err http://us.archive.ubuntu.com hardy-updates/multiverse sun-java6-jdk 6-07-3ubuntu2
404 Not Found [IP: 91.189.88.140 80]  
Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/multiverse/s/sun-java6/sun-java6-jdk_6-07-3ubuntu2_i386.deb  404 Not Found [IP: 91.189.88.140 80]  
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

When I run:

$ /media/disk/School/java/hw1$ javac HelloWorldApp,java  </pre>

I get:

The program 'javac' can be found in the following packages:  
 * java-gcj-compat-dev  
 * openjdk-6-jdk  
 * gcj-4.2  
 * kaffe  
 * ecj  
 * jikes-sun  
 * jikes-sablevm  
 * j2sdk1.4  
 * jikes-classpath  
 * jikes-gij  
 * gcj-4.1  
 * sun-java5-jdk  
 * jikes-kaffe  
 * sun-java6-jdk  
Try: sudo apt-get install <selected package>  
bash: javac: command not found

When I try to update (using sudo apt-get update) I get:

E: The method driver /usr/lib/apt/methods/https could not be found.

Has anyone else encountered this problem? Thanks in advance...

+4  A: 

You can install the JDK on recent versions of Ubuntu by typing this command:

sudo apt-get install sun-java6-jdk

You might find this easier than attempting to set it up manually.

Matthew Talbert
added this info to original post...
danwoods
@danwoods: you probably haven't got an up-to-date index. Try "sudo apt-get update" and then try to install again.
Joachim Sauer
Apparently the problem is bigger than I thought. I added the results of that command to my original post
danwoods
A: 

Usually you will find java in the PATH and not javac in a standard Ubuntu installation. This is primarily because of the gcj package that gets installed. Symlinks are also created that can be updated using the update-alternatives script.

After an installation of Sun JDK, you are required to update the symlink to java, and this is usually done via a command similar to the one below

sudo update-alternatives --config java
If hardlinks to the location of (Sun) java is not present, you can create it using a command similar to
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_07/jre/bin/java 300

In the case of javac, you can create a symlink, again using update-alternatives using:

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_07/bin/javac 300

This will make javac available on PATH, just like java.

Of course, there is option of updating the PATH variable via a simple export or via changes to the shell configuration file.

Vineet Reynolds
I don't believe this is true in the latest versions of Ubuntu. Installing as I mention above should install javac and make it accessible without any symlinks at all.
Matthew Talbert
I haven't verified it on 9.04. But I've done this on versions 6.x-7.x. Probably not on 8.x. But I have the foggiest of memories for configuration issues across versions.
Vineet Reynolds
Well, I think 8.04 was the first version to include official sun .debs. These work much better than trying to install manually, as was necessary on previous versions.
Matthew Talbert
Ah ok! I normally don't use debs for installing Java - pick the installers straight off java.sun.com.
Vineet Reynolds
+1  A: 

The instructions you posted seem overly complex. Try this:

  1. Download the Java SDK into $HOME/archives (e.g., $HOME/archives/jdk-6u16-linux-x64.bin).
  2. Extract Java into /opt (or another location if you do not want to use root). For example:

    cd /opt
    chmod 755 $HOME/archives/jdk-6u16-linux-x64.bin
    sudo $HOME/archives/jdk-6u16-linux-x64.bin

  3. Create a symbolic link (to ease upgrades):

    sudo ln -s jdk1.6.0_16 jdk

  4. Edit $HOME/.bashrc

  5. Append the following lines:

    JAVA_HOME=/opt/jdk
    PATH=$PATH:$JAVA_HOME/bin

  6. Reload the environment variables:

    source $HOME/.bashrc

You should now be able to compile programs.

I prefer this method to installing the managed package because uninstalling (or upgrades) never seems to remove all bits of the SDK flawlessly, and it seems to hinder installing multiple versions of the Java Software Development Kit on the same machine at the same time. I have had issues with apt-get and Java in the past. Also, this method allows me to be absolutely certain which version of Java is in use at any time.

If you are not comfortable using root and /opt, you can use your own account and $HOME/bin/jdk instead. Change the .bashrc file accordingly.

Remove any version of Java you previously had installed. You might need to restart your terminal session.

This works for all versions of Java since at least Java 1.2.

Dave Jarvis
This method actually works. Although it may seem to be overly complex.
Dananjaya
A: 

The installation worked for me

just uninstall older versions of java and try to install again

sudo apt-get install sun-java6-jdk

it will work

thanks guys

Pratyay Modi