๐ป How to Download and Install Java on Mac and Ubuntu – Step-by-Step Guide
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
Post a Comment