12
Feb

Software installation made easy on the Mac with Brew


Welcome to the Technovangelist. This time I want to show you a tool that is
critical to what I do. In my role as an evangelist and technical
instructor I am constantly building demo apps and complex systems. And that means installing lots of different
tools. On a Mac the easiest way to install software
is through a utility called brew. Brew, or home brew is a package manager for
the Mac . Folks have defined packages for most of the more common tools and applications
that you are likely to ever need on a Mac. That includes more behind the scenes tools
like curl or git or gatsby or the fish shell, and friendlier applications like vscode or
1password or chrome. You can even use it to install most fonts
and everything on the Mac App Store. In this video I will show you how to get started
with brew, what it is actually doing, and how I use it on a daily basis. You are watching another video from the technovangelist. On this channel, I talk about the tools and
technologies that I use to get my job done. If you find topics like this interesting,
consider subscribing. Oh and hit that like button to let me know
I am doing something you appreciate. So lets get started by finding it on the web. Go to brew.sh in your web browser. You should see a page something like this. Now to install it, you just copy a command
from that page into the terminal on your Mac. The easiest way to start the terminal is to
just press command space and type terminal then press enter. When that is all done you can start using
brew to install cool tools. Lets say you are started using bitbar to have
a custom widget in your menubar, or bettertouchtool to customize your Touch Bar, or maybe even
ubersicht or geek tool to customize your desktop. And you want a simple weather widget to show
up. Now sure there are plenty of weather widgets
that you can put in all these places, but you want to do something super custom. So there are a number of weather apis out
that, many of which have a free plan. Openweathermap is one of them but whatever
you choose, you are probably going to have to work with a json document because that’s
what most of these apis put out. So how do you start to work with json on the
command line. There are three common ways to work with that
an http call to get json on the command line. You can use curl which is super powerful but
a bit painful to use if you don’t use it everyday. Though it is probably already installed on
your system. There is wget which I feel is a little more
friendly but you will probably need to install it somehow. And then the prettiest is httpie which you
will definitely need to install but it makes working with this stuff much easier and, well,
prettier. Lets start with curl. So run curl. Hmmm, not useful. Try curl –help. Perhaps even less useful. Try using the man pages that are built in
to most unix oriented systems. Type man curl. great. Now I see how every command line option could
be used, but I don’t really know how to perform the api call. Thankfully there are a number of man alternatives. One of the best in my opinion is tldr. Well, since this video is actually about brew,
lets install it with brew. Usually you can guess the right command to
use: brew install and then whatever you want to install. So brew install tldr. Within a few seconds its installed and ready
to go. Tldr curl. Cool, now I have a bunch of examples of ways
to use curl. Turns out I can just run curl followed by
the url and I should get back the json, assuming the api method is a get. For this video rather than dealing with api
keys, I am going to use an example api that you can find at dummy.restapiexample.com. so if I type curl followed by the url for
the list of employees at this dummy api site I get this jumble of data. Hmmm, not super useful. You could copy this and paste it into something
like vs code but it may be easier to process it with another tool. Jq is a great little utility to work with
json. So lets run brew install jq to install it,
then run tldr jq to figure out how to use it. Now run that last curl command and pipe the
output to jq. Wow, that is a lot prettier. Now if that’s all we needed to do, using a
tool like httpie might be easier. Run brew install httpie then run httpie followed
by that url. You’ll see that we have similar output but
also a pretty output of all the http headers. But we don’t just need the json. We will need a single data point out of the
json that we can then use. If we just want the status we could use .status. if we want all the items in the data, we could
say .data or .data then open and close square brackets. If we want all the employee names we could
use .data brackets .employee _ name. Or if we want one specific name, we could
add the index to the array. The hardest thing here is learning how to
filter json but you can read the actual docs to get good at that. Now there is a problem with one of the first
commands we ran. Using brew is not always the best way to install
something. Try out the command tldr –version. It says 1.30 and with a date of 2016. But if you look at the tldr website, you will
see that the most mature client is the nodejs client and that was last updated a couple
months ago. Every now and then you will run into software
that installs an older version when you use brew. And unfortunately there isn’t a good way to
tell which is good vs bad. For instance installing docker via brew will
get you a much older version. But most things installed via brew are great
and you get the latest versions with no real effort. So I will remove tldr using brew uninstall
tldr, then install it the right way using npm I -g tldr. So not only is it super easy to install apps,
its also super easy to uninstall apps. I mentioned that you can also install other
tools with brew. We spent some time playing with apis at the
command line. One of the best tools to use to play around
with more complex apis is called postman. And we can install it using brew cask. A few years ago, you had to install cask after
brew, but now it comes built in. Just type brew cask install postman and within
a few seconds you can start playing around with postman. Its just as easy to install vs code, or google
chrome, or omnifocus, or screen flow. Of course if you are installing products like
omnifocus or screen flow you better have a license. Brew won’t help you get around staying legal. I also like to install different fonts and
brew is perfect for installing them. But first we have to add a tap, which is an
alternate source of formulae for brew. So run brew tap homebrew slash cask-fonts. Then brew cask install and whatever font you
want to install. Jet brains just released a great new font
called jetbrains mono. So to install it on my system I can run brew
cask install jet brains dash mono. Now you might look at all of this and think,
well, its not that hard to download and install all of this the normal way. But it gets a lot more interesting when you
script it all. Lets say you are using a Mac book pro at work
and they just updated you to a new machine. You could run a single script with all the
tools that you use and within a few minutes all of your tools are installed. You don’t have to go to search around the
web and install everything individually. Great, except maybe you have a bunch of apps
that are installed from the Mac App Store. Well, if you run brew install mas and then
run mas list you will see all the apps you have installed from the App Store and can
add those lines to your script. Ok, that’s a bit of a pain. Generating that file and then keeping it up
to date can be time consuming. So type brew bundle dump and your script will
be generated for you based on what is currently installed. Now copy that script over to your new machine,
install brew, and then run brew bundle to have everything installed for you. That is pure magic and saves a whole heap
of time. But what is brew doing? Well each brew formula is simply a ruby file
that defines some metadata about the package, defines dependencies and conflicts, and then
runs each of the steps you would have to run normally. There is no magic, it just automates the steps. What are some of the things I do with it? Well, recently I installed a tool for dealing
with multiple kubernetes contexts called kubectx. And immediately put it to use as I sometimes
find myself jumping back and forth from a local rancher cluster, to minikube, to a cluster
on aws. When I needed minikube, I installed it with
brew. I needed telnet to get onto one of my filehubs
that for some reason didn’t support ssh. And there are so many other tools that I try
really quickly than remove right away. I think brew is one of those amazing tools
that everyone should be familiar with if you are using a Mac. My name is Matt Williams and I am the technovangelist. Please consider subscribing if you find topics
like this interesting and I look forward to seeing you in my next video.

Tags: , , , , , , , , , , , , , , , , , , ,

There are no comments yet

Why not be the first

Leave a Reply

Your email address will not be published. Required fields are marked *