Setting up your Macbook for Java development 101

Gayan Perera
Mac O’Clock
Published in
3 min readJul 21, 2020

In this story, I will walk through how I set up my Macbook Pro for Java development. The decisions I took while setting up my Macbook are based on security concerns and little bit of my personal taste.

As a person who worked many years on Linux world, I’m kind of used to command-line tools when it comes to this task. For example, I use things like nvm, sdkman to manage my java, nodejs versions. On Linux you can install a lot of tools from the distribution repositories as well. Package managers like dnf, apt are among my favorites when it comes to installing tools like git, svn etc.

We will start by looking at package managers for macOS first. Because we need that to install things like git, java for example.

Package Manager

When it comes to MacOS there are mainly two famous package managers. They are Homebrew and Macports. You can read more information about them at https://www.macports.org and https://brew.sh. Also if you are interested to know the difference between these two you can read the following https://www.quora.com/What-are-the-differences-between-MacPorts-and-Homebrew.

I choose Homebrew because it downloads fewer dependencies and it has simple version management compared to Macports. But I didn’t go with the default Homebrew installation. I used a custom installation of Homebrew. This is because the default Homebrew installation change file permission of /usr/local folder and add it as the first path entry when searching for commands in PATH variable. You will find many articles on the internet talking about this risk.

I choose to install my package managers like Homebrew and sdkman into /opt/pkg folder. This folder must be own by your user and it should have access to wheel group.

Following commands will help you to create the folder with correct permissions.

sudo mkdir /opt/pkg
sudo chown <username> /opt/pkg
sudo chmod u+rwx /opt/pkg
sudo chmod g+rwx /opt/pkg
sudo chmod a+r /opt/pkg

Now the folder is ready to install package managers.

How to perform a more secure custom Homebrew installation

  • First, you need git in your Macbook. For this, you can install the Apple provided git version with xcode cli tools. To install this you can just open a terminal and just type git --version . This will install the xcode cli tools and Apple git with it.
  • Now go into /opt/pkg
cd /opt/pkg
  • Now clone the homebrew repository into /opt/pkg folder with the following command
git clone https://github.com/Homebrew/brew.git homebrew
  • Add the new /opt/pkg/homebrew/bin to path. Make sure the path is not added as the first path since we don’t want to override any system tools from homebrew. Add the following to your ~/.zshrc file
export PATH=$PATH:/opt/pkg/homebrew/bin

You can learn more about Homebrew at https://brew.sh and I would also recommend you know the difference about brew and brew cask by reading https://apple.stackexchange.com/questions/125468/what-is-the-difference-between-brew-and-brew-cask

How to install SDKMAN

By default, the sdkman (http://sdkman.io/) installs into your home directory. But I didn’t want sdkman in my home directory. So i decided to install it inside /opt/pkg. Here is how to do it.

  • Run the following command
export SDKMAN_DIR="/opt/pkg/sdkman" && curl -s get.sdkman.io | bash

This will install sdkman into /opt/pkg/sdkman. That's it now you have a sdkman installation ready to use.

That's it for this story. Now you have a Macbook with two package managers, actually one is a sdk manager, which are ready to use to install different softwares and sdks you need for development. In the next story, we will look at how to install different sdks, tools like IDEs, for example, using these package and sdk managers.

See you in the next story 👋

--

--