How to back up your Mac config and apps from Terminal (using brew, conda, pip and mackup)
Published: 2022-12-10 21:39:44

---
title: How to back up your Mac config and apps from Terminal (using brew, conda, pip and mackup)
published: true
date: 2022-12-01 14:00:00 UTC
tags: 
canonical_url: https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/
---

When you are using you Mac daily you begin to use several apps almost without thinking. But when you have to migrate to new Mac (or Linux) you realize how many apps and custom settings are you missing.

- [Context](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#context)
- [Brew](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#brew)
  - [Export apps to a Brewfile](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#export-apps-to-a-brewfile)
  - [Import (install) apps from a Brewfile](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#import-install-apps-from-a-brewfile)
- [Conda](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#conda)
  - [Export 1 (one) conda environment (env)](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#export-1-one-conda-environment-env)
  - [Export all conda environments (env) in one command](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#export-all-conda-environments-env-in-one-command)
  - [Create a conda env from a YAML file](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#create-a-conda-env-from-a-yaml-file)
- [Mackup](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#mackup)
- [PIP](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#pip)
- [References](https://diegocarrasco.com/how-to-back-up-your-mac-config-and-apps-from-terminal-using-brew-conda-pip-and-mackup/#references)

### Context

I want to back up my Mac settings and be able to use or restore them in the same or another Mac. I mean Mac because:

1. brew is mainly used in Mac, but also [available in Linux and WSL](https://docs.brew.sh/Homebrew-on-Linux)) and
2. [mackup](https://github.com/lra/mackup) is mainly for macOS (but should also support Linux)

We will back up the following tool sets:

- brew packages as a list of installed packages
- conda environments
- all apps supported by mackup
- pip packages

### [Brew](https://brew.sh/)

#### Export apps to a Brewfile

```
brew bundle dump # dump the app list to the current directory

brew bundle dump --file=~/Brewfile # dump the app list to a specific location 

```

#### Import (install) apps from a Brewfile

```
brew bundle --file=~/.private/Brewfile

```

### Conda

#### Export 1 (one) conda environment (env)

To export just one environment you can do the following:

```
conda activate my_env
conda env export > my_env.yml
conda deactivate

```

#### Export all conda environments (env) in one command

But usually you have several environments (at least I do) and you would want to export all of them at the same time. In that case, you may do the following [source](https://stackoverflow.com/a/60509631/624088)

```
for env in $(conda env list | cut -d" " -f1); do 
   if [[${env:0:1} == "#"]] ; then continue; fi;
   conda env export -n $env > ${env}.yml
done

```

#### Create a conda env from a YAML file

This will create a .yml file with the name of the env for each of the envs you have.

To create an environment from a .yml file

```
conda env create -f environment.yml

```

### [Mackup](https://github.com/lra/mackup)

```
mackup backup # to backup
mackup restore # to restore

```

### PIP

To export all the dependencies in a python environment

```
pip freeze > requirements.txt

```

tT import (or install) all the dependencies from a text-file

```
pip install -f requirements.txt

```

## References

- [https://tomlankhorst.nl/brew-bundle-restore-backup/](https://tomlankhorst.nl/brew-bundle-restore-backup/)
- [https://github.com/lra/mackup/tree/master/doc](https://github.com/lra/mackup/tree/master/doc)
- [export all created conda environments](https://stackoverflow.com/questions/60508333/export-all-created-conda-environments)