Setting JAVA_HOME on Ubuntu

Describes how to set JAVA_HOME on Ubuntu.

--java is assumed to go through alternatives. --/ usr / bin / java-> / etc / alternatives / java-> (actual java location) --PATH is in / usr / bin, so it doesn't correspond in particular. --When switching between multiple javas, make it possible to handle it by executing the source command. --See here for how to switch. "Install and switch between multiple Javas on Ubuntu"

manner

Create java_home.sh under /etc/profle.d

--The shell under /etc/profile.d is executed at login.

sudo vi /etc/profile.d/java_home.sh

Described export of JAVA_HOME

--The JDK home directory is determined from the absolute path of the java command. --There are cases of $ {JAVA_HOME} / bin / java and $ {JAVA_HOME} / jre / bin / java, so both are supported. (There may be other cases ...)

/etc/profile.d/java_home.sh


export JAVA_HOME=`echo $(dirname $(readlink $(readlink $(which java)))) | sed -e 's/\/bin$//g' | sed -e 's/\/jre$//g'`

Reflect JAVA_HOME with source command

source /etc/profile.d/java_home.sh

Verification

echo $JAVA_HOME

Recommended Posts

Setting JAVA_HOME on Ubuntu
tmux on Ubuntu
Web Bluetooth on Ubuntu20.04
Reinstall Kubernetes on Ubuntu 19.10
Use Flutter on Ubuntu
Install pyqt5 on ubuntu
Install Ruby on Ubuntu 20.04
Install Autoware on Ubuntu 18.04.5
Put JetBrains on Ubuntu
Use mkdir on ubuntu
Apache2 on Ubuntu20.04 LTS
Use cpplapack on ubuntu
ubuntu on wsl part 10
Install Homebrew on Ubuntu 20.04
Run tiscamera on Ubuntu 18.04
Build Zabbix on Ubuntu 20.04
Using Flutter on Ubuntu (Part 2)
Create SSL certificate on Ubuntu 18.04
Building WebGIS on Ubuntu20.04 LTS
Install OpenJDK7 (JAVA) on ubuntu 14.04
Put Ubuntu 20.04.1 on Raspberry Pi 4
Install Cybozu Office 10 on Ubuntu 20.4
Extend swap area on Ubuntu 18.04
Install Docker on Ubuntu Server 20.04
Ubuntu on Windows Community Preview
Japanese input on Ubuntu20.04 Desktop
Oracle Java 8 on Docker Ubuntu
Install zabbix agent (5.0) on Ubuntu 18.04
Install MAV Proxy on Ubuntu 18.04
Install Arudino IDE on Ubuntu 20
Record video on ubuntu18.04 LTS
Introduced knowledge (wiki) on Ubuntu
Installing OpenMX on Ubuntu 18.04.5 LTS
Install Java on WSL Ubuntu 18.04
Ruby installation on WSL2 + Ubuntu 20.04
Install Ubuntu Desktop 20.10 on RaspberryPi4
Run chromium-mir-kiosk on Ubuntu Core
Install Arduino IDE on Ubuntu 20.04
Ubuntu on Windows build speed
Run java applet on ubuntu
Install raspi-config on Ubuntu 20.04 (LTS)
Install WordPress 5.5 on Ubuntu 20.04 LTS
Run Eclipse CDT on Ubuntu
Set up ansible-playbook on Ubuntu 20.04
Install PlantUML on Intellij on Ubuntu
Install Ubuntu Server 20.04 on Btrfs
Note: Install PostgreSQL 9.5 on Ubuntu 18.04
Try setting up Talend Open Studio on Amazon EC2 (ubuntu)
Java_HOME setting for paths with spaces
Install AWS IoT Greengrass on Ubuntu
Installing Ruby + Rails on Ubuntu 18.04 (rbenv)
Build the latest Samba 4 on Ubuntu 20.04
Note: setting javaMail on Raspberry Pi
How to use Bio-Formats on Ubuntu 20.04
Build a XAMPP environment on Ubuntu
How to install WildFly on Ubuntu 18.04
Preparing to use electron-react-boilerplate on Ubuntu 20.4
Set JAVA_HOME correctly on Mac OS 10.12
Install MQTT broker Mosquitto on Ubuntu 18.04
Enable Java 8 and Java 11 SDKs on Ubuntu
Install SonarQube on ECS instance on Ubuntu 16.04