I had to setup MacOS on a new laptop this weekend, and this is how I usually do it.
Every time I need to configure a new dev environment, it is a PITA, so I decided to write down the steps in the correct order so I can visit it in the future when I need to do it again.
The steps to setup macOS
- OS update
- Install Xcode
- Install command line tools
- Accept the Xcode license
- Install Chrome
- Install homebrew
- Install iTerm
- Configure git global
- Install GitX
- Create a new SSH key
- Install ASDF and Ruby
- Install redis
- Install Postgres
- Postgres client
- ImageMagick
- Handle unexpected errors
- Install Heroku CLI
- Install Google Cloud CLI
- Install code editors
- Configure .dotfiles
- Install other browsers
1. OS update
Before starting the setup macOS it is wise to update the macOS.
Let’s do it first.
2. Install Xcode
I don’t use Xcode for web development, but I prefer to install it and have it ready, just in case.
3. Install command line tools
This is the most essential portion of Xcode; the command-line tools will be required for most of the development work on macOS, including Ruby, which is the language I use.
It brings the compilers that most of the development work needs, including the C compilers needed by Ruby.
$ xcode-select --install
4. Accept the Xcode license
Yes, it is weird but useful; just run the code below and accept it before getting angry with annoying messages.
$ sudo xcodebuild -license
After doing it, you need to close the terminal window and open it again.
5. Install Chrome
I use Chrome for work due to the available extensions.
I also install and use other browsers daily, but Chrome is the main one.
6. Install homebrew
Homebrew is “the” package manager for macOS; I will use it many times in this guide, and you will probably need it for other things as well.
You can get up-to-date instructions at the homebrew homepage, but today I used:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
7. Install iTerm2
I realized that Apple Terminal evolved, and it is fine now, but I have used iTerm2 for a long time and don’t have plans to stop using it.
BTW, take the opportunity to donate.
I don’t remember doing it very often, but I donate what I can every time I need to install it.
8. Configure Git global
I have a .dotfiles
with more configurations, but this is the first.
$ git config --global user.name "YOUR NAME"
$ git config --global user.email "YOU@DOMAIN.COM"
That way Git is usable.
9. Install GitX
I have tried several alternatives for git UI clients over the years, but I can get rid of GitX ๐คทโโ๏ธ
The old and good GitX download page is not working anymore, so I thought: “this is it”; time to move on.
Fortunately, this wasn’t the case, and I found a fork maintained by heroes at https://github.com/gitx/gitx
10. Create a new SSH key
New laptop, new SSH key, or not ๐
But this time I created one:
$ ssh-keygen -t ed25519 -C "your@email.com"
11. Install ASDF and Ruby
I have used rvm and rbenv in the past, and both work fine.
But recently, my preference has been to asdf.
ASDF requires coreutils:
$ brew install coreutils
Then, the ruby plugin and version:
$ asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
$ asdf install ruby 3.3.0
I had an issue installing Ruby 3.3.0 with the psych
extension; it was the lack of libyaml so I installed it via homebrew:
$ brew install libyaml
You may want to install OpenSSL as well; I didn’t need it this time, but usually, I have to install it:
$ brew install openssl
You can install other languages like:
12. Install Redis
It seems like we may soon have alternatives to Redis, but for now, I still use it in the current projects.
$ brew install redis
# to run redis automatically at login
$ brew services start redis
13. Install Postgres
This is the database I use the most now.
I like the Postgres.app
It is installed just like any other macOS app.
But for using it in Ruby on Rails applications, we need to install a dependency (libpq):
$ brew install libpq
14. Postgres client
There are a few good GUI clients, but I like TablePlus.
15. ImageMagick
Manipulating images.
$ brew install imagemagick
16. Handling unexpected errors on setup macOS
Every time I setup macOS for a new dev environment, errors pop up; this time I had an error regarding a Ruby version and MacOS.
# error
+[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
# solution
# add the folowing to .bash_profile or .zprofile
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
https://github.com/rails/rails/issues/38560
17. Install Heroku CLI
We use Heroku for hosting our apps, so:
$ brew tap heroku/brew && brew install heroku
18. Install Google Cloud CLI
Another portion of our infrastructure is on Google Cloud.
https://cloud.google.com/sdk/docs/install-sdk
19. Install code editors
The long-time companion MacVim.
The new kid on the block VSCode.
With the Vim emulator extension vsccodesim.
20. Configure .dotfiles
I used YADR for many years, and I still use it on my other dev laptop, but this time I decided to go light and configured only the following three manually.
- .gitconfig
- .vimrc
- .zshrc
21. Install more browsers
A web developer carries multiple browsers on a toolbelt.
I always have:
This is it. A new laptop is ready to go ๐ช
Was it useful for you?
If so, consider following me on Twitter at @renatonitta.
And feel free to drop a comment or a question below ๐.