From dc2c92c5cd32f22f3e360206defd2bc1cf5e1d1d Mon Sep 17 00:00:00 2001 From: Adrian Stoica <george.a.stoica@ntnu.no> Date: Mon, 2 Sep 2019 13:43:22 +0200 Subject: [PATCH] added java install info for linux and mac --- howto/get-java.md | 146 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/howto/get-java.md b/howto/get-java.md index 781140e..c2aa844 100644 --- a/howto/get-java.md +++ b/howto/get-java.md @@ -83,6 +83,52 @@ Open a terminal window and type java -version ``` +#### Extract downloaded binary + +After the download finishes you have in the destination folder the `.tar.gz` file with a name like this `openjdk-12.0.2_linux-x64_bin.tar.gz` . + +Extract the files and place them in the desired location with the following commands + + +``` bash +tar zxvf openjdk-12.0.2_linux-x64_bin.tar.gz +sudo mkdir /usr/lib/jvm +sudo mv jdk-12.0.2 /usr/lib/jvm/ +``` + +#### Set up the environment variables + +create a shell script in /etc/profile.d + +``` bash +sudo nano /etc/profile.d/jdk.sh +``` + +add the following lines inside the file and save and close + +``` bash +export JAVA_HOME=/usr/lib/jvm/jdk-12.0.2 +export PATH=$PATH:$JAVA_HOME/bin + +``` + +apply changes + +logout and log back in or run the script you have just created + +``` bash +bash /etc/profile.d/jdk.sh +``` + + +check if everything is in order + +``` bash +echo $JAVA_HOME +java -version +``` + + ### MacOs @@ -94,6 +140,106 @@ Open a terminal window and type java -version ``` +#### Extract downloaded binary + +After the download finishes you have in the destination folder the `.tar.gz` file with a name like this `openjdk-12.0.2_osx-x64_bin.tar.gz`. + +Extract the files using the following command + +``` bash +tar xf openjdk-12.0.2_osx-x64_bin.tar.gz +``` + +Move the extracted to the folder `/Library/Java/JavaVirtualMachines/` +You will need to execute the move with super user privileges in order to put the files in the system folder + +``` bash +sudo mv jdk-12.0.2 /Library/Java/JavaVirtualMachines/ +``` + + +#### Set up the environment variables + +To set up the environment variable `JAVA_HOME` we will need to edit the `.bash_profile` file in the home directory. + +If the file mentioned does not exist we can create it with the following command: + +``` bash +touch ~/.bash_profile +``` + +We need to export the `JAVA_HOME` variable so we edit the file using + +``` bash +edit ~/.bash_profile +``` + +we add the following line + +`export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-12.0.2/Contents/Home"` + +finally we save the changes and close the file. To apply the changes we need to run the following command + +``` bash +source ~/.bash_profile +``` + + +## Using sdkman + +sdkman is a tool that allows you to manage development kits including JDK. It is possible to run it on Linux and Mac without additional software. On windows one can use it after installing Git Bash and MinGW. +Refer to the https://sdkman.io webpage for more info and instructions + +### Installation on supported systems - open a terminal window and enter: + +``` bash +curl -s "https://get.sdkman.io" | bash +``` + +Follow the instructions on-screen to complete installation. + +Apply changes by entering: + +``` bash +source "$HOME/.sdkman/bin/sdkman-init.sh" +``` + +check the version using the command + +``` bash +sdk version +``` + +If the tool is now properly installed the result of the previous command will be: + +``` bash + sdkman 5.x.x +``` + + +### Typical usage + +After installation you will typically use commands like + +``` bash +sdk list java +``` +list the available versions + +``` bash +sdk install java +``` +install latest java, add version number to install specific java + +``` bash +sdk use java 12.0.2 +``` +use the java development kit with version 12.0.2 + + +See more commands on the sdkman.io site + + ## Download Java -- GitLab