Setting Up Your macOS Development Environment and Automating Backups.
Tags: development, setup, macbook, rails
Published: 2024-01-27 07:44:59

---
title: Setting Up Your macOS Development Environment and Automating Backups.
published: true
description: Install Apps and auto backup your Brewfile on Github.
tags: development,setup,macbook,rails
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2024-01-27 07:05 +0000
---
![Worli Sea link at Dusk in Mumbai India](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2sx9oiblmjstlxzapgpk.jpeg)

## Setting Up Your macOS Development Environment and Automating Backups.

My Repo : [My-Mac-Settings](https://github.com/AnjanJ/my-mac-settings)

I recently got a new M3 Max 14" for myself and wanted to port over all my setup from earlier 14" M1 pro. Hence I came up with below scripts to make things easy for me.

Please leave your suggestions & thoughts.

In this comprehensive guide, I'll walk you through the process of setting up a robust development environment on your macOS system. I'll cover everything from installing essential tools and applications to automating the backup of critical configuration files.

My Brewfile contains all the apps installed via Homebrew, Macapp Store and also all of my VSCode extensions.

Then we will use the script `auto_update_Brewfile.sh` to update & upgrade brew formulae and apps installed using Homebrew. It also backups `.zshrc` file if it has been changed in past week.

## Below are the paid apps I am using.
You can go through the entire list of apps in my [Brewfile](https://github.com/AnjanJ/my-mac-settings/blob/main/Brewfile) and remove or add apps as per your need. 

### AlDente Pro

AlDente Pro is a premium application designed to manage your MacBook's battery and charging effectively. It optimizes your battery's lifespan and keeps you informed about its health. Learn more about it [here](https://apphousekitchen.com/).

### iStat Menus

iStat Menus offers real-time monitoring of your Mac's performance, including CPU usage, memory utilization, and network statistics. It's a powerful tool for keeping an eye on your system's health. Explore it further [here](https://bjango.com/mac/istatmenus/).

### Raycast

Raycast is a productivity powerhouse that replaces Spotlight and provides quick access to a wide range of functions. It enhances your workflow and simplifies everyday tasks. Discover more about it [here](https://www.raycast.com/).

### Warp Terminal.
[Warp](https://www.warp.dev/) is free for now and my goto terminal app which replaced iTerm for me. Its beautiful and very easy to use, I have paired it up with a free app called [Fig.io](https://fig.io/)

## The Heart of the Setup: `setup_dev_env.sh` Script

The `setup_dev_env.sh` script is a powerful automation tool for macOS. It's designed to perform the following tasks:

1. Check for and install Homebrew.
2. Download a Brewfile from a specified URL.
3. Use Homebrew to install all the software listed in the Brewfile.

## Initial Steps: Downloading and Running the Script

**Downloading the Script:** You can either clone the script from a [my repository](https://github.com/AnjanJ/my-mac-settings) or copy-paste it directly from the [here](https://raw.githubusercontent.com/AnjanJ/my-mac-settings/main/Brewfile).

**Hosting the Brewfile:** Your Brewfile, which lists all the desired software and packages, should be hosted online and accessible via a direct URL. This URL is used by the script to download the Brewfile.

**Modifying and Executing the Script:** After downloading, modify the script to include the URL of your Brewfile. Then, run the script in the terminal after giving it execute permissions using `chmod +x setup_dev_env.sh`.

## Automating Brewfile Backups with Crontab

An essential part of managing a development environment is keeping your software list up to date. This is where the [`auto_update_Brewfile.sh`](https://github.com/AnjanJ/my-mac-settings/blob/main/auto_update_Brewfile.sh) script comes in, coupled with cron jobs for automation.

**Setting Up Cron Jobs:** Use `crontab -e` to edit your cron jobs. Add a line to schedule the backup script to run at specific times, like every Friday and Sunday at 7 PM.

You can check if there are any present cron tasks or your changes have been made correctly or not by using `crontab -l` command. 
It will show output as below.
![Terminal showing output of crontab -l command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ek0kgrinryvbtaff751i.png)

**Script Execution and Permissions:** Make sure the backup script is executable by using `chmod +x auto_update_Brewfile.sh`.

**Backup and Update:** The script updates brew formulae, upgrades installed apps, backs up the old Brewfile, generates a new one, back ups .zshrc file if it has been changed in past week and pushes the updates to a specified GitHub repository.

## Troubleshooting and Tips

- Regularly check your cron jobs and script logs to ensure they're running as expected.

- Test the scripts manually before relying on the automated schedule.

## Conclusion

With the setup and automation described in this guide, you can easily maintain a robust development environment on your macOS system. Plus, you'll have peace of mind knowing that your essential configuration files are automatically backed up on GitHub.

Start by forking [My-Mac-Settings](https://github.com/AnjanJ/my-mac-settings) and following the steps outlined here or in the readme. Enjoy your optimized macOS experience!

![AJ's WFH setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lzoz1s8eot8e4hmuxd43.png)