DEV Community

Cover image for Setting your default browser via Command Line in macOS
Maria Campbell
Maria Campbell

Posted on • Updated on

Setting your default browser via Command Line in macOS

Photo by Designecologist on pexels.com

This post was originally published on my personal blog mariadcampbell.com.

Table of Contents

Installing the Homebrew package defaultbrowser

In order to set my default browser in macOS via Command Line, I first
had to install the Homebrew package called defaultbrowser.

First, I ran the following commands, one after the other:

brew update
brew upgrade
Enter fullscreen mode Exit fullscreen mode

This is similar to what we do in Linux Mint when we run
sudo apt update and sudo apt upgrade to make sure that all our
packages are up to date before installing a new one. We have to do
the same with Homebrew.

brew install defaultbrowser

Next, I run the following command to install the defaultbrowser
package:

brew install defaultbrowser
Enter fullscreen mode Exit fullscreen mode

Running the defaultbrowser safari command

After it was successfully installed, I quit the active Terminal window
and opened up a new instance. And there, I ran the following command to
make Safari my default browser:

defaultbrowser safari
Enter fullscreen mode Exit fullscreen mode

And that was it!

No more need to go into browser settings searching for the location
where to set a particular browser as your default browser. You can just
set it by typing a simple two word command in Terminal!

Top comments (1)

Collapse
 
ahmedjaad profile image
Ahmed Jaad

Cool stuff, I’d definitely do it. If you use a tool like Karabiner I’d add how to add a shortcut for even quicker switch. It’d definitely make this post more spicy