Skip to main content
removing last xargs dirname was needed for it to work better
Source Link

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

script source

This is sufficient to have a configured java enviroment, there's no need to set the PATH variable, as it's already managed by the alternatives framework.

Cheers F.

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

script source

This is sufficient to have a configured java enviroment, there's no need to set the PATH variable, as it's already managed by the alternatives framework.

Cheers F.

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

script source

This is sufficient to have a configured java enviroment, there's no need to set the PATH variable, as it's already managed by the alternatives framework.

Cheers F.

Updating the JAVA_HOME variable with a more portable script
Source Link
trane77
  • 158
  • 1
  • 5

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

export#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(dirnamereadlink -nf $(which java) | xargs dirname `readlink| -fxargs /etc/alternatives/java`)dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

It can bescript source

This is sufficient to have a good solution if you don't switch version many timesconfigured java enviroment, plus you don'tthere's no need to cut & paste any pathset the PATH variable, as it's already managed by the alternatives framework.

Cheers F.

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

export JAVA_HOME=$(dirname $(dirname `readlink -f /etc/alternatives/java`))

It can be a good solution if you don't switch version many times, plus you don't need to cut & paste any path.

Cheers

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

script source

This is sufficient to have a configured java enviroment, there's no need to set the PATH variable, as it's already managed by the alternatives framework.

Cheers F.

Use block code formatting instead of inline code
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Why not set the current java version with:

sudo update-alternatives --config java sudo update-alternatives --config javac

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

export JAVA_HOME=$(dirname $(dirname `readlink -f /etc/alternatives/java`))

export JAVA_HOME=$(dirname $(dirname `readlink -f /etc/alternatives/java`))

It can be a good solution if you don't switch version many times, plus you don't need to cut & paste any path.

Cheers

Why not set the current java version with:

sudo update-alternatives --config java sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

export JAVA_HOME=$(dirname $(dirname `readlink -f /etc/alternatives/java`))

It can be a good solution if you don't switch version many times, plus you don't need to cut & paste any path.

Cheers

Why not set the current java version with:

sudo update-alternatives --config java
sudo update-alternatives --config javac

(and whatever else java binary you need)

Then set the following in your .bashrc or .zshrc:

export JAVA_HOME=$(dirname $(dirname `readlink -f /etc/alternatives/java`))

It can be a good solution if you don't switch version many times, plus you don't need to cut & paste any path.

Cheers

Source Link
trane77
  • 158
  • 1
  • 5
Loading