Skip to content

How To Install Postman On Mac Using Cli

API Testing Blog

Installing Postman on Mac Using the Command Line

Postman is a popular API testing tool that allows you to send requests, view responses, and manage your API workflows. While Postman offers a user-friendly graphical interface, you can also install and manage it using the command line. This approach can be beneficial for automation, scripting, and integrating Postman into your existing development workflows.

Prerequisites

  • Homebrew: Ensure you have Homebrew installed on your Mac. Homebrew is a package manager for macOS that simplifies the process of installing and managing software. If you haven’t installed it yet, you can find instructions on the official Homebrew website: https://brew.sh/

Steps to Install Postman on Mac Using CLI

  1. Open the Terminal: Locate and open the Terminal application on your Mac. You can find it by searching for “Terminal” in Spotlight.

  2. Install Postman with Homebrew: In the Terminal, enter the following command and press Enter:

Terminal window
brew install postman
  1. Verify Installation: Once the installation is complete, you can verify that Postman is available by typing:
Terminal window
postman

This command will launch the Postman application.

Launching Postman from the Command Line

After installing Postman, you can launch it from the Terminal using the postman command.

Terminal window
postman

Alternatively, you can use the open command to automatically open Postman in the default web browser:

Terminal window
open postman://

Customizing Postman Installation

If you prefer to install a specific version of Postman, you can use the --version flag with the brew install command.

Terminal window
brew install postman --version=8.12.2

This will install Postman version 8.12.2.

Updating Postman

To update Postman to the latest version, use the following command:

Terminal window
brew upgrade postman

Uninstalling Postman

If you need to remove Postman from your system, use the following command:

Terminal window
brew uninstall postman

Utilizing Postman on the CLI

While the graphical interface of Postman is convenient for interactive testing, the CLI offers enhanced capabilities for automated testing, scripting, and integration.

Sending Requests using the CLI

You can use the postman command to send various types of HTTP requests, such as GET, POST, PUT, PATCH, DELETE, and more.

For example, to send a GET request to the Google homepage, you would use the following command:

Terminal window
postman get https://www.google.com

The command sends a GET request to the specified URL and prints the response in the terminal.

Specifying headers and body

You can further customize your requests by adding headers, body parameters, and other options using the --header, --data, and other flags:

Terminal window
postman post https://api.example.com/users \
--header "Content-Type: application/json" \
--data '{"name": "John Doe", "email": "john.doe@example.com"}'

Using Postman Collections

For more complex API testing workflows, you can utilize Postman collections, which are grouped sets of requests with specific parameters and configurations. To execute a collection from the command line, you need to export it as a JSON file. Then, use the following command:

Terminal window
postman run my_collection.json

This command runs the collection specified in my_collection.json.

Creating a Postman Collection using CLI

You can create a Postman collection using the following command:

Terminal window
postman collection create <collection_name>

For example:

Terminal window
postman collection create my-new-collection

Adding Requests to a Collection

To add requests to a created collection, use the following command:

Terminal window
postman collection add <collection_name> <request_name> <request_method> <request_url>

For example:

Terminal window
postman collection add my-new-collection GetUsers GET https://api.example.com/users

Save the Collection

To save a collection to a JSON file, run the following command:

Terminal window
postman collection export <collection_name> > my-collection.json

Run the collection:

Terminal window
postman run my-collection.json

This command will run all the requests listed in the my-collection.json file.

Summary

Installing Postman through the command line provides a streamlined approach for managing and automating your API testing workflow on your Mac. The postman command allows you to send requests, manage collections, and integrate Postman into your scripts for efficient and comprehensive API testing.

API Testing Blog