How to Install Jenkins on Mac

July 13, 2022

Introduction

Jenkins is an open-source automation server with numerous plugins that facilitate Continuous integration/delivery and deployment (CI/CD). It runs in servlet containers, and it is used to build and test software.

Jenkins allows organizations to accelerate and automate the software development process. The automation makes it easier for developers to integrate changes and users to obtain fresh builds.

In this tutorial, you will learn to install Jenkins on macOS.

How to install Jenkins on Mac - tutorial.

Prerequisites

How to Install Jenkins on Mac

There are two methods for installing Jenkins on Mac. Choose the Homebrew method for a CLI-based installation or run Jenkins through Docker.

Method 1: Install Jenkins Using the Homebrew Package Manager

Homebrew is a macOS package manager that lets users install software using the CLI.

Follow the steps below to install Jenkins via Homebrew:

Step 1: Install Homebrew

Homebrew is not installed by default. To check whether you have Homebrew installed, run the following command in the terminal:

brew --version

The output should return the version installed. If not installed, follow our tutorial to install Homebrew on macOS and then proceed to install Jenkins.

Step 2: Check if Java is Installed

A JDK installation is required for Jenkins to work. Check if Java is installed on your Mac by running:

java -version

If Java isn't installed, a dialog box appears stating that Java needs to be installed. Install the latest Java SDK by running:

brew install java

Homebrew installs the JDK files and directories at /usr/local/Cellar/openjdk/.

Step 3: Install Jenkins

1. Press Command + Space Bar and type "Terminal". Click the Terminal icon to open the app.

Open the terminal on macOS.

2. Run the following command to download and install the latest Jenkins LTS version:

brew install jenkins-lts
Installing Jenkins using homebrew on Mac.

Step 4: Start the Jenkins Server

1. Before setting up and using Jenkins, start the Jenkins server. Run:

brew services start jenkins-lts
Starting the Jenkins server on Mac using homebrew.

By default, Jenkins runs on port 8080.

2. Check if the server was started properly by browsing to http://localhost:8080/.

Jenkins server started, but requires the administrator password.

If Jenkins starts properly, a message appears asking for the administrator password.

Step 5: Unlock Jenkins

After the installation, Jenkins is locked until the administrator securely sets it up.

Follow the steps below to obtain the admin password, log in, and unlock Jenkins:

1. In the terminal, use the cat command to view the log file containing the password. The syntax is:

cat /Users/[user]/.jenkins/secrets/initialAdminPassword

For [user], specify your user ID.

For example:

cat /Users/marko/.jenkins/secrets/initialAdminPassword
Obtaining the administrator password after Jenkins installation.

2. Copy the password from the log file, paste it into the Jenkins login form, and click Continue to log in.

Unlocking Jenkins using the administrator password.

Complete the setup by configuring Jenkins. Follow the instructions below in the How to Configure Jenkins on Mac section of the article.

Method 2: Install Jenkins Using Docker

Docker is an open-source platform for building, deploying, and managing containerized apps. Jenkins is part of the service products that can run on Docker.

Follow the steps below to install Docker and Jenkins on Mac:

Step 1: Install Docker on Mac

Browse to the official Docker Desktop installation page for macOS. Choose and follow through with the appropriate installation instructions depending on your processor type - Intel or Apple Silicon.

Install Docker on Mac - choose which chip you have.

Step 2: Install Jenkins

After installing Docker, open the terminal and run the following command to download and install Jenkins:

docker run -p 8080:8080 -p 50000:50000 -v ~/jenkins_home:/var/jenkins_home jenkins/jenkins:lts
Install Jenkins on Mac using Docker.

Docker downloads the latest LTS Jenkins image and creates a new Docker container in which it starts Jenkins.

  • The docker run command runs the Jenkins image as a container.
  • The -p flag maps the local 8080 and 50000 ports to the Docker container 8080 and 50000 ports, allowing you to open the http://localhost:8080/ address on the local machine and use it to log into Jenkins.
  • The -v ~jenkins_home:/var/jenkins_home argument creates a jenkins_home volume and mounts it under the /var/jenkins_home path in the container. Mounting the volume creates a read/write filesystem, allowing any changes made to the container to persist each time you run the command.
  • The jenkins/jenkins:lts argument is the Docker image used to create the container - in this case, it is the latest LTS Jenkins image pulled from the jenkins repository.

The output contains the Docker administrator password - make sure to copy the password for the next step:

Copy the administrator password from the Jenkins installation output.

Step 3: Unlock and Run Jenkins

Browse to http://localhost:8080/ to log in to the Jenkins server. Paste the administrator password you copied in the previous step and click Continue.

Note: Master an important aspect of Jenkins with our ultimate guide on Jenkins environment variables.

How to Configure Jenkins on Mac

After installing Jenkins, customize the installation and modify Jenkins' behavior with different plugins and extensions. Jenkins plugins and extensions include SCM implementations (integrating Git, Subversion, or Perforce into Jenkins), single sign-on systems, job type annotations, and many more.

Follow the steps below to configure Jenkins:

Step 1: Customize Jenkins

After browsing to http://localhost:8080/ and entering the administrator password, proceed with customizing Jenkins by choosing one of the two options:

  • Select the Install suggested plugins to install all the most popular and most used plugins.
  • To install only certain plugins, select the Select plugins to install option and install only the ones you need.
Customize Jenkins by installing suggested plugins.

Selecting the Install suggested plugins option automatically installs the most used plugins. Wait for the installation to complete.

Plugins for Jenkins installing during server setup.

Step 2: Create a Jenkins User

After installing the plugins, Jenkins prompts you to create the first admin user. Enter the required details and click Save and Continue to proceed to the next step.

Creating the first admin user in Jenkins.

Step 3: Configure the Jenkins URL

After creating the admin user, configure the Jenkins server URL. The default URL is http://localhost:8080/, and it is already filled in. If you want to keep the default server URL, click Save and Finish to complete the Jenkins configuration.

Setting up the Jenkins default URL.

After completing the configuration, the server is ready for use, and you can start creating new jobs from the main page.

Jenkins server welcome screen.

How to Stop and Restart Jenkins on Mac

Stop Jenkins Using Homebrew

If you installed and started Jenkins using Homebrew, run the following command to stop the Jenkins server:

brew services stop jenkins-lts
Stopping the Jenkins server using homebrew.

Restart the Jenkins server by running the brew services start jenkins-lts command.

Stop Jenkins via Docker

Stop Jenkins by navigating to the terminal window where you ran the Docker container and press Command + C. The process running the Docker container stops, which also stops the Jenkins server.

Stopping the Jenkins server via Docker.

Restart Jenkins by running the docker run command for the Jenkins server. The command runs the same container created during the installation, and any changes made persist each time the server is run.

To start a new Jenkins server, start a new Docker container.

How to Uninstall Jenkins on Mac?

If you have installed Jenkins using Homebrew, run the following command to uninstall it completely:

brew uninstall jenkins-lts --force
Uninstall Jenkins from Mac using homebrew.

Clean up the dependencies and remaining files by running:

brew cleanup
Cleaning up Jenkins dependencies after uninstalling.

The command removes Jenkins from the system, along with all the residual files.

Conclusion

This tutorial showed how to install Jenkins on Mac in two different ways and configure the server to start automating. Use Jenkins as a powerful and practical tool to build, check, and deploy software projects.

Next, learn the difference between Jenkins and Kubernetes, or get started with Jenkins with our Jenkins basics for beginners tutorial.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Change Jenkins Home Directory
February 10, 2022

The Jenkins Home directory contains Jenkins deployment logs, cloned repositories, and configurations. See how to change the Jenkins Home directory location.
Read more
Jenkins Shared Library: How to Create, Configure and Use
February 3, 2022

Jenkins is an open-source solution for automating software development. Jenkins Shared Libraries allow developers to reuse scripts for multiple projects.
Read more
Jenkins Build: Set Up Freestyle Project in Jenkins
January 25, 2022

Jenkins uses projects to help developers automate coding and deployment. This tutorial shows you how to create a freestyle project in Jenkins.
Read more
Jenkins Logs - Viewing and Customizing
December 30, 2021

Jenkins is an open-source automation server for code development. Jenkins logs offer a wealth of information about your projects and the Jenkins app itself.
Read more
  • © 2022 Copyright phoenixNAP | Global IT Services. All Rights Reserved.