This tutorial shows how to prepare your local machine for Java development, including developing Java apps that run on Google Cloud. Follow these steps to install Java and relevant tools.
Objectives
- Install a JDK (Java Development Kit).
- Install a build automation tool.
- Install the gcloud CLI.
- (Optional) Install an IDE or editor.
- (Optional) Install IDE Google Cloud plugin.
- Install the Cloud Client Libraries for Java.
- Set up authentication.
Install a JDK (Java Development Kit)
You may choose any Java distribution of your choice by ensuring that the following environment variables are set:
- JAVA_HOME: Points to the base of the JDK installation.
- PATH: Includes
$JAVA_HOME/bin.
Eclipse Temurin is the recommended OpenJDK (Java Development Kit) distribution for use with Google Cloud. Temurin is open-source licensed, Java SE TCK-certified, and tested to ensure production-quality performance and security.
(Recommended) Installing Temurin
Temurin's installation instructions vary by operating system.
- Binaries are available for download.
- For Docker containers, use the official 'eclipse-temurin' image.
If you are using Compute Engine boot images, you can use the following installation scripts.
CentOS/RHEL/Rocky
- Determine the major version of CentOS/RHEL/Rocky Linux:
eval "$(grep VERSION_ID /etc/os-release)" eval "$(grep ^ID= /etc/os-release)" OLD_IFS=$IFS IFS='.' read -ra split_version <<< "$VERSION_ID" IFS=$OLD_IFS MAJOR_VERSION=$split_version
- Create the Adoptium source repo file, `/etc/yum.repos.d/adoptium.repo`:
sudo tee /etc/yum.repos.d/adoptium.repo << EOM [Adoptium] name=Adoptium baseurl=https://packages.adoptium.net/artifactory/rpm/$ID/$MAJOR_VERSION/\$basearch enabled=1 gpgcheck=1 gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public EOM
- Update package lists:
sudo yum update -y
- Install Temurin:
sudo yum install -y temurin-17-jdk
- Verify installation:
java -version
Debian/Ubuntu
- Install the public repo GPG key. If you are using Ubuntu 16.4, pass the key
through
gpg --dearmorbefore saving to file. (ex:sudo wget ... | gpg --dearmor | sudo tee ...)sudo mkdir -p /etc/apt/keyrings sudo wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
- Determine the name of the Linux distribution, and create the source list file,
/etc/apt/sources.list.d/adoptium.list:eval "$(grep VERSION_CODENAME /etc/os-release)" sudo tee /etc/apt/sources.list.d/adoptium.list << EOM deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $VERSION_CODENAME main EOM
- Update package lists:
sudo apt update -y
- Install Temurin: