I mainly use the Homebrew to manage almost every app or program, even apps on the App Store using mas. It becomes a bit of a pain when I set up a new MacBook because it takes time for me to look for the list of the apps and programs on my main MacBook and install one them by one on my new MacBook.
I recently figured out a handy way to set up brew formulas in a new device using homebrew-bundle and symbolic link bash command.
This post is written based on an assumption that you already have brew
installed and actively using it on your Mac.
Step 1. Save your current settings in .dotfiles/mac/Brewfile
I use .dotfiles
folder to save settings (dotfiles, config files, etc.) and it's saved on my private GitHub repository.
The explanation will be based on my setting.
1. Create the source folders and Brewfile
mkdir --parents ~/.dotfiles/mac && touch ~/.dotfile/mac/Brewfile
2. Create a symlink to the ~/Brewfile
# the target file will be generated automatically
ln -s ~/.dotfiles/mac/Brewfile ~/Brewfile
Why'd you be bothered to create extra ./Brewfile
? Because brew bundle
command that we're going to use a lot uses ~/Brewfile
by default.
You can specify the path to the Brewfile
inside the .dotfiles/mac
folder, or the path of whatever source folder you use for your setting at the end of the command with --file
flag:
# in my case
brew bundle install --file=~/.dotfiles/mac/Brewfile
However, I just prefer to keep things simple regarding the commands and not touch my source file if I can.
3. Whenever you remove/install new formulas on your main Mac, dump your new bundle settings to the ~/Brewfile
; it will update ~/.dotfiles/mac/Brewfile
automatically.
# need to force because the file already exists
brew bundle dump --force
FYI: any changes you make on any of the two linked files will be applied to one another, but deleting the target file(linked file) won't remove the source file.
Step 2. (on your new MacBook) copy the .dotfiles
folder and create a symlink to ~/Brewfile
As I mentioned earlier, you can specify the path to the source Brewfile
and not create a symlink.
1. paste .dotfiles
folder to a new mac (~/.dotfiles)
2. install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
3. create a symlink to ~/Brewfile
from the Brewfile
inside .dotfiles
folder
ln -s ~/.dotfiles/mac/Brewfile ~/Brewfile
4. install bundles from ~/Brewfile
brew bundle install
All good and ready!
Top comments (0)