Instalando Java en Ubuntu

Hola a todos, como ya saben desde que Oracle se hizo de Sun incluyendo el tan afamado Java, Oracle no ha perdido el tiempo así que, aunque sigue siendo libre de uso (por el momento) ya dejo de ser libre para distribución, es decir, que Oracle no permite que terceros distribuyan la máquina virtual, así que ya solo puede distribuirse Open JDK pero no Oracle JDK.

Entonces les dejo un pequeño script para poder instalar Oracle JDK y estar disponible desde update-java-alternatives.

install-java

Usage: install-java -h JAVA_HOME -n JAVA_NAME

This script configure java on linux systems with support
update-alternatives and update-java-alternatives

OPTIONS:
-h set path of Java Home
-n set name used of alternative configuration
-a set java like default


Para instalar necesitas descargar la maquina virtual de Java de Oracle de preferencia el *.bin y ejecutarlo sobre el directorio que prefieras (les recomiendo en /opt/ para estar más organizado) y una ves descomprimido el archivo ejecuta:

sudo ./install-java -h /opt/jdk1.6... -n java-6-oracle -a

Espero y les sea de utilidad…

Anuncios

2 pensamientos en “Instalando Java en Ubuntu

  1. Hola,
    nos ha sido de mucha ayuda este post. Hemos utilizado el script, pero hemos hecho algunas modificaciones para que se pueda utilizar con JRE en vez de JDK y con arquietectura diferentes a amd64.

    Usage: install-java -h JAVA_HOME -n JAVA_NAME -a ARCH [-c] [-k]

    This script configure java on linux systems with support
    update-alternatives and update-java-alternatives

    OPTIONS:
    -h set path of Java Home
    -n set name used of alternative configuration
    -c set java like default
    -k if is JDK
    -a define architecture (i386, ${ARCH},…)

    Aquí está el script:

    #!/bin/bash

    java_apply=false
    java_home=
    java_name=
    JDK=
    ARCH=

    usage() {
    cat << EOF

    Usage: install-java -h JAVA_HOME -n JAVA_NAME -a ARCH [-c] [-k]

    This script configure java on linux systems with support
    update-alternatives and update-java-alternatives

    OPTIONS:
    -h set path of Java Home
    -n set name used of alternative configuration
    -c set java like default
    -k if is JDK
    -a define architecture (i386, ${ARCH},…)

    EOF
    }

    if [ $# -eq 0 ] ; then
    usage
    exit
    fi

    while getopts “:ch:n:ka:” optname
    do
    case $optname in
    “a”) ARCH=$OPTARG
    ;;
    “k”) JDK=”jre/”
    ;;
    “c”)
    java_apply=true
    ;;
    “h”)
    java_home=$OPTARG
    ;;
    “n”)
    java_name=$OPTARG
    ;;
    \?)
    echo “”
    echo “Invalid option: \”-$OPTARG\””
    echo “Check help”
    usage
    exit 1
    ;;
    🙂
    echo “”
    echo “Option \”-$OPTARG\” requires an argument.”
    echo “Check help”
    usage
    exit 1
    ;;
    esac
    done

    shift $(($OPTIND – 1))

    if [ “$*” != “” ] ; then
    echo “”
    echo “Argument \”$*\” invalid”
    echo “Check help”
    usage
    exit 1
    fi

    if [ “$ARCH” == “” ] ; then
    echo “”
    echo “Require a option \”-a\””
    echo “Check help”
    usage
    exit 1
    fi

    if [ “$java_home” == “” ] || [ “$java_name” == “” ] ; then
    echo “”
    echo “Require a options \”-h\” and/or \”-n\””
    echo “Check help”
    usage
    exit 1
    fi

    if [ ! -f “$java_home/bin/java” ] ; then
    echo “”
    echo “Invalid JAVA_HOME = “$java_home
    echo “”
    exit 1
    fi

    if [ -f “/usr/lib/jvm/.”$java_name”.jinfo” ] ; then
    echo “”
    echo “JAVA_NAME = “$java_name” already exists”
    echo “”
    exit 1
    fi

    mkdir -p /usr/lib/jvm
    ln -fs $java_home “/usr/lib/jvm/”$java_name

    cat < “/usr/lib/jvm/.”$java_name”.jinfo”
    name=$java_name
    alias=$java_name
    priority=1000
    section=non-free

    jre ControlPanel /usr/lib/jvm/$java_name/${JRE}bin/ControlPanel
    jre java /usr/lib/jvm/$java_name/${JRE}bin/java
    jre java_vm /usr/lib/jvm/$java_name/${JRE}bin/java_vm
    jre javaws /usr/lib/jvm/$java_name/${JRE}bin/javaws
    jre jcontrol /usr/lib/jvm/$java_name/${JRE}bin/jcontrol
    jre keytool /usr/lib/jvm/$java_name/${JRE}bin/keytool
    jre pack200 /usr/lib/jvm/$java_name/${JRE}bin/pack200
    jre policytool /usr/lib/jvm/$java_name/${JRE}bin/policytool
    jre rmid /usr/lib/jvm/$java_name/${JRE}bin/rmid
    jre rmiregistry /usr/lib/jvm/$java_name/${JRE}bin/rmiregistry
    jre unpack200 /usr/lib/jvm/$java_name/${JRE}bin/unpack200
    jre orbd /usr/lib/jvm/$java_name/${JRE}bin/orbd
    jre servertool /usr/lib/jvm/$java_name/${JRE}bin/servertool
    jre tnameserv /usr/lib/jvm/$java_name/${JRE}bin/tnameserv
    jre jexec /usr/lib/jvm/$java_name/${JRE}lib/jexec
    jdk appletviewer /usr/lib/jvm/$java_name/bin/appletviewer
    jdk apt /usr/lib/jvm/$java_name/bin/apt
    jdk extcheck /usr/lib/jvm/$java_name/bin/extcheck
    jdk idlj /usr/lib/jvm/$java_name/bin/idlj
    jdk jar /usr/lib/jvm/$java_name/bin/jar
    jdk jarsigner /usr/lib/jvm/$java_name/bin/jarsigner
    jdk javac /usr/lib/jvm/$java_name/bin/javac
    jdk javadoc /usr/lib/jvm/$java_name/bin/javadoc
    jdk javah /usr/lib/jvm/$java_name/bin/javah
    jdk javap /usr/lib/jvm/$java_name/bin/javap
    jdk jconsole /usr/lib/jvm/$java_name/bin/jconsole
    jdk jdb /usr/lib/jvm/$java_name/bin/jdb
    jdk jhat /usr/lib/jvm/$java_name/bin/jhat
    jdk jinfo /usr/lib/jvm/$java_name/bin/jinfo
    jdk jmap /usr/lib/jvm/$java_name/bin/jmap
    jdk jps /usr/lib/jvm/$java_name/bin/jps
    jdk jrunscript /usr/lib/jvm/$java_name/bin/jrunscript
    jdk jsadebugd /usr/lib/jvm/$java_name/bin/jsadebugd
    jdk jstack /usr/lib/jvm/$java_name/bin/jstack
    jdk jstat /usr/lib/jvm/$java_name/bin/jstat
    jdk jstatd /usr/lib/jvm/$java_name/bin/jstatd
    jdk native2ascii /usr/lib/jvm/$java_name/bin/native2ascii
    jdk rmic /usr/lib/jvm/$java_name/bin/rmic
    jdk schemagen /usr/lib/jvm/$java_name/bin/schemagen
    jdk serialver /usr/lib/jvm/$java_name/bin/serialver
    jdk wsgen /usr/lib/jvm/$java_name/bin/wsgen
    jdk wsimport /usr/lib/jvm/$java_name/bin/wsimport
    jdk xjc /usr/lib/jvm/$java_name/bin/xjc
    plugin mozilla-javaplugin.so /usr/lib/jvm/$java_name/${JRE}lib/${ARCH}/libnpjp2.so
    EOF

    update-alternatives –quiet –install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/$java_name/${JRE}lib/${ARCH}/libnpjp2.so 100
    update-alternatives –quiet –install /usr/bin/appletviewer appletviewer /usr/lib/jvm/$java_name/bin/appletviewer 100 –slave /usr/share/man/man1/appletviewer.1 appletviewer.1 /usr/lib/jvm/$java_name/man/man1/appletviewer.1
    update-alternatives –quiet –install /usr/bin/apt apt /usr/lib/jvm/$java_name/bin/apt 100 –slave /usr/share/man/man1/apt.1 apt.1 /usr/lib/jvm/$java_name/man/man1/apt.1
    update-alternatives –quiet –install /usr/bin/extcheck extcheck /usr/lib/jvm/$java_name/bin/extcheck 100 –slave /usr/share/man/man1/extcheck.1 extcheck.1 /usr/lib/jvm/$java_name/man/man1/extcheck.1
    update-alternatives –quiet –install /usr/bin/idlj idlj /usr/lib/jvm/$java_name/bin/idlj 100 –slave /usr/share/man/man1/idlj.1 idlj.1 /usr/lib/jvm/$java_name/man/man1/idlj.1
    update-alternatives –quiet –install /usr/bin/jar jar /usr/lib/jvm/$java_name/bin/jar 100 –slave /usr/share/man/man1/jar.1 jar.1 /usr/lib/jvm/$java_name/man/man1/jar.1
    update-alternatives –quiet –install /usr/bin/jarsigner jarsigner /usr/lib/jvm/$java_name/bin/jarsigner 100 –slave /usr/share/man/man1/jarsigner.1 jarsigner.1 /usr/lib/jvm/$java_name/man/man1/jarsigner.1
    update-alternatives –quiet –install /usr/bin/javac javac /usr/lib/jvm/$java_name/bin/javac 100 –slave /usr/share/man/man1/javac.1 javac.1 /usr/lib/jvm/$java_name/man/man1/javac.1
    update-alternatives –quiet –install /usr/bin/javadoc javadoc /usr/lib/jvm/$java_name/bin/javadoc 100 –slave /usr/share/man/man1/javadoc.1 javadoc.1 /usr/lib/jvm/$java_name/man/man1/javadoc.1
    update-alternatives –quiet –install /usr/bin/javah javah /usr/lib/jvm/$java_name/bin/javah 100 –slave /usr/share/man/man1/javah.1 javah.1 /usr/lib/jvm/$java_name/man/man1/javah.1
    update-alternatives –quiet –install /usr/bin/javap javap /usr/lib/jvm/$java_name/bin/javap 100 –slave /usr/share/man/man1/javap.1 javap.1 /usr/lib/jvm/$java_name/man/man1/javap.1
    update-alternatives –quiet –install /usr/bin/jconsole jconsole /usr/lib/jvm/$java_name/bin/jconsole 100 –slave /usr/share/man/man1/jconsole.1 jconsole.1 /usr/lib/jvm/$java_name/man/man1/jconsole.1
    update-alternatives –quiet –install /usr/bin/jdb jdb /usr/lib/jvm/$java_name/bin/jdb 100 –slave /usr/share/man/man1/jdb.1 jdb.1 /usr/lib/jvm/$java_name/man/man1/jdb.1
    update-alternatives –quiet –install /usr/bin/jhat jhat /usr/lib/jvm/$java_name/bin/jhat 100 –slave /usr/share/man/man1/jhat.1 jhat.1 /usr/lib/jvm/$java_name/man/man1/jhat.1
    update-alternatives –quiet –install /usr/bin/jinfo jinfo /usr/lib/jvm/$java_name/bin/jinfo 100 –slave /usr/share/man/man1/jinfo.1 jinfo.1 /usr/lib/jvm/$java_name/man/man1/jinfo.1
    update-alternatives –quiet –install /usr/bin/jmap jmap /usr/lib/jvm/$java_name/bin/jmap 100 –slave /usr/share/man/man1/jmap.1 jmap.1 /usr/lib/jvm/$java_name/man/man1/jmap.1
    update-alternatives –quiet –install /usr/bin/jps jps /usr/lib/jvm/$java_name/bin/jps 100 –slave /usr/share/man/man1/jps.1 jps.1 /usr/lib/jvm/$java_name/man/man1/jps.1
    update-alternatives –quiet –install /usr/bin/jrunscript jrunscript /usr/lib/jvm/$java_name/bin/jrunscript 100 –slave /usr/share/man/man1/jrunscript.1 jrunscript.1 /usr/lib/jvm/$java_name/man/man1/jrunscript.1
    update-alternatives –quiet –install /usr/bin/jsadebugd jsadebugd /usr/lib/jvm/$java_name/bin/jsadebugd 100 –slave /usr/share/man/man1/jsadebugd.1 jsadebugd.1 /usr/lib/jvm/$java_name/man/man1/jsadebugd.1
    update-alternatives –quiet –install /usr/bin/jstack jstack /usr/lib/jvm/$java_name/bin/jstack 100 –slave /usr/share/man/man1/jstack.1 jstack.1 /usr/lib/jvm/$java_name/man/man1/jstack.1
    update-alternatives –quiet –install /usr/bin/jstat jstat /usr/lib/jvm/$java_name/bin/jstat 100 –slave /usr/share/man/man1/jstat.1 jstat.1 /usr/lib/jvm/$java_name/man/man1/jstat.1
    update-alternatives –quiet –install /usr/bin/jstatd jstatd /usr/lib/jvm/$java_name/bin/jstatd 100 –slave /usr/share/man/man1/jstatd.1 jstatd.1 /usr/lib/jvm/$java_name/man/man1/jstatd.1
    update-alternatives –quiet –install /usr/bin/native2ascii native2ascii /usr/lib/jvm/$java_name/bin/native2ascii 100 –slave /usr/share/man/man1/native2ascii.1 native2ascii.1 /usr/lib/jvm/$java_name/man/man1/native2ascii.1
    update-alternatives –quiet –install /usr/bin/rmic rmic /usr/lib/jvm/$java_name/bin/rmic 100 –slave /usr/share/man/man1/rmic.1 rmic.1 /usr/lib/jvm/$java_name/man/man1/rmic.1
    update-alternatives –quiet –install /usr/bin/schemagen schemagen /usr/lib/jvm/$java_name/bin/schemagen 100 –slave /usr/share/man/man1/schemagen.1 schemagen.1 /usr/lib/jvm/$java_name/man/man1/schemagen.1
    update-alternatives –quiet –install /usr/bin/serialver serialver /usr/lib/jvm/$java_name/bin/serialver 100 –slave /usr/share/man/man1/serialver.1 serialver.1 /usr/lib/jvm/$java_name/man/man1/serialver.1
    update-alternatives –quiet –install /usr/bin/wsgen wsgen /usr/lib/jvm/$java_name/bin/wsgen 100 –slave /usr/share/man/man1/wsgen.1 wsgen.1 /usr/lib/jvm/$java_name/man/man1/wsgen.1
    update-alternatives –quiet –install /usr/bin/wsimport wsimport /usr/lib/jvm/$java_name/bin/wsimport 100 –slave /usr/share/man/man1/wsimport.1 wsimport.1 /usr/lib/jvm/$java_name/man/man1/wsimport.1
    update-alternatives –quiet –install /usr/bin/xjc xjc /usr/lib/jvm/$java_name/bin/xjc 100 –slave /usr/share/man/man1/xjc.1 xjc.1 /usr/lib/jvm/$java_name/man/man1/xjc.1
    update-alternatives –quiet –install /usr/bin/ControlPanel ControlPanel /usr/lib/jvm/$java_name/${JRE}bin/ControlPanel 100
    update-alternatives –quiet –install /usr/bin/java java /usr/lib/jvm/$java_name/${JRE}bin/java 100
    update-alternatives –quiet –install /usr/bin/java_vm java_vm /usr/lib/jvm/$java_name/${JRE}bin/java_vm 100
    update-alternatives –quiet –install /usr/bin/javaws javaws /usr/lib/jvm/$java_name/${JRE}bin/javaws 100
    update-alternatives –quiet –install /usr/bin/jcontrol jcontrol /usr/lib/jvm/$java_name/${JRE}bin/jcontrol 100
    update-alternatives –quiet –install /usr/bin/keytool keytool /usr/lib/jvm/$java_name/${JRE}bin/keytool 100
    update-alternatives –quiet –install /usr/bin/pack200 pack200 /usr/lib/jvm/$java_name/${JRE}bin/pack200 100
    update-alternatives –quiet –install /usr/bin/policytool policytool /usr/lib/jvm/$java_name/${JRE}bin/policytool 100
    update-alternatives –quiet –install /usr/bin/rmid rmid /usr/lib/jvm/$java_name/${JRE}bin/rmid 100
    update-alternatives –quiet –install /usr/bin/rmiregistry rmiregistry /usr/lib/jvm/$java_name/${JRE}bin/rmiregistry 100
    update-alternatives –quiet –install /usr/bin/unpack200 unpack200 /usr/lib/jvm/$java_name/${JRE}bin/unpack200 100
    update-alternatives –quiet –install /usr/bin/orbd orbd /usr/lib/jvm/$java_name/${JRE}bin/orbd 100
    update-alternatives –quiet –install /usr/bin/servertool servertool /usr/lib/jvm/$java_name/${JRE}bin/servertool 100
    update-alternatives –quiet –install /usr/bin/tnameserv tnameserv /usr/lib/jvm/$java_name/${JRE}bin/tnameserv 100
    update-alternatives –quiet –install /usr/bin/jexec jexec /usr/lib/jvm/$java_name/${JRE}lib/jexec 100

    if [ $java_apply = true ] ; then
    update-java-alternatives -s $java_name
    fi

  2. Que bien, intentare generar una versión mejor para considerar otras plataformas y la versión JRE… gracias por el aporte…

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s