Installing homebrew

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Updating homebrew

$ brew update

Upgrading homebrew

$ brew upgrade

Troubleshooting

$ brew doctor

Installing mongodb formula

$ brew install mongodb

To start mongodb formula

$ brew services start mongodb

To stop mongodb formula

$ brew services stop mongodb

To restart restart formula

$ brew services restart mongodb

Saving installed brew and cask formula list

$ brew list >> brew.txt
$ brew cask list >> brewcask.txt

brew.txt brewcask.txt

Restore brew and cask formula list from a backup file

$ brew install $(< packages.txt )
$ brew install $(cat packages.txt)
$ cat packages.txt | xargs brew install