Getting Java JDK to compile on ubuntu

I'm trying to get started with Java, but so far I have not been able to get it on my machine. I would love to compile from the command line. Following the instructions here without errors, I cannot compile with javac . Here is what I still have:

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...

+6
java linux
source share
4 answers

You can install the JDK in recent versions of Ubuntu by typing the following command:

 sudo apt-get install sun-java6-jdk 

You may find this easier than trying to manually configure it.

+6
source share

Try the following:

  • Download the Java SDK in $ HOME / archives (e.g. $ HOME / archives / jdk-6u16-linux-x64.bin).
  • Extract Java in / opt (or another place 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

  • Create a symlink (to facilitate updating):

    sudo ln -s jdk1.6.0_16 jdk

  • Edit $ HOME / .bashrc

  • Add the following lines:

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

  • Reload the environment variables:

    source $ HOME / .bashrc

Now you can compile programs.

I prefer this method of installing a managed package because uninstalling (or updating) never deletes all bits of the SDK flawlessly and seems to prevent you from installing multiple versions of the Java Software Development Kit on the same computer at the same time. I had problems with apt-get and Java in the past. In addition, this method allows me to be absolutely sure which version of Java is used at any time.

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

Uninstall any version of Java you previously installed. You may need to restart the terminal session.

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

+5
source share

You will usually find java in PATH, not javac in a standard Ubuntu installation. This is primarily due to the gcj package that is being installed. Symbolic links are also created that can be updated using script update alternatives.

After installing Sun JDK, you need to update the symbolic link to java, and this is usually done with a command similar to the following

sudo update-alternatives --config java

If there are no hard links to the location of (Sun) java, 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 symbolic link 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 the option of updating the PATH variable with a simple export or with changes to the shell configuration file.

+1
source share

I just ran into this problem when installing the html validator from http://validator.nu . To install sun-java6-jdk I had to add this repository: deb http://archive.canonical.com/ lucid partner

To complete the verification installation, I had to install (export) my $JAVA_HOME to /usr/lib/jvm/java6-sun .

Change the clear to whatever suits your version of Ubuntu.

0
source share

All Articles