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.
Prerequisites
- A computer running macOS (or see how to Install Jenkins on Windows, Debian 10 (Buster), CentOS 8, Ubuntu 18.04).
- Java installed.
- An account with administrator privileges.
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.
2. Run the following command to download and install the latest Jenkins LTS version:
brew install jenkins-lts
Step 4: Start the Jenkins Server
1. Before setting up and using Jenkins, start the Jenkins server. Run:
brew services start jenkins-lts
By default, Jenkins runs on port 8080.
2. Check if the server was started properly by browsing to http://localhost:8080/.
Note: See how to change the default Jenkins port.
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
2. Copy the password from the log file, paste it into the Jenkins login form, and click Continue to log in.
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:
Note: See how to configure Docker in Jenkins.
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.
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
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 local8080
and50000
ports to the Docker container8080
and50000
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 ajenkins_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 thejenkins
repository.
The output contains the Docker administrator password – make sure to copy the password for the next step:
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.
Selecting the Install suggested plugins option automatically installs the most used plugins. Wait for the installation to complete.
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.
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.
After completing the configuration, the server is ready for use, and you can start creating new jobs from the main page.
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
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.
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
Clean up the dependencies and remaining files by running:
brew cleanup
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.
Đăng ký liền tay Nhận Ngay Bài Mới
Subscribe ngay
Cám ơn bạn đã đăng ký !
Lỗi đăng ký !
Add Comment