๐Ÿ’ป How to Download and Install Java on Mac and Ubuntu – Step-by-Step Guide

How to Download and Install Java on Mac and Ubuntu

Java is not just a programming language—it’s the base of many big applications across mobile, web, and enterprise systems. But before we dive into our Java coding journey, let’s first install Java properly.

This post will help you install Java (OpenJDK) on:

  • ✅ macOS
  • ✅ Ubuntu (Linux)

๐Ÿ Part 1: Install Java on macOS

We’ll use Homebrew, a popular package manager for macOS.

๐Ÿ› ️ Step-by-step instructions:

✅ Step 1: Check if Homebrew is installed

brew -v

If it’s not installed, run the following:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

✅ Step 2: Install OpenJDK

brew install openjdk@21

✅ Step 3: Add Java to your system PATH

For zsh users (macOS default shell):

echo 'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

For bash users:

echo 'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

✅ Step 4: Confirm Java installation

java -version

You should see:

openjdk 21 2023-09-19

๐ŸŽ‰ Java is installed successfully!

๐Ÿง Part 2: Install Java on Ubuntu

๐Ÿ› ️ Step-by-step instructions:

✅ Step 1: Open Terminal

Press Ctrl + Alt + T to launch it.

✅ Step 2: Update your package list

sudo apt update

✅ Step 3: Install OpenJDK 21

sudo apt install openjdk-21-jdk

✅ Step 4: Verify installation

java -version

Expected output:

openjdk 21 2023-09-19

๐ŸŽ‰ You're done! Java is installed.

๐Ÿง  Bonus: Set JAVA_HOME (Optional but helpful)

On macOS:

export JAVA_HOME=$(/usr/libexec/java_home -v21)

Add this to ~/.zshrc or ~/.bash_profile to persist.

On Ubuntu:

echo "export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> ~/.bashrc
source ~/.bashrc

๐Ÿ What’s Next?

Now that Java is installed, you’re all set to write and run your first Java program!

๐Ÿ‘‰ Coming up next on Code Tulika:

  • ๐Ÿ” JDK vs JRE vs JVM – Desi Style Explanation
  • ๐Ÿ‘จ‍๐Ÿ’ป Hello World in Java
  • ๐Ÿง  Java Project Setup + IDE (VS Code / IntelliJ)

๐Ÿ“Œ Stay Tuned

๐ŸŽฅ YouTube Channel: Code Tulika
๐Ÿง  Tagline: Will teach in deep with funny funday
๐Ÿ“š Blog: TulikaHub.com

Comments

Popular posts from this blog

Java Episode 3 – Understanding JDK, JRE & JVM in Simple Desi Style