Skip to content

MacOS

A question that comes to mind for every beginner: How to set up my environment for data-science?

The following guide will teach you how to set up a minimal development environment for MacOS.

Prerequisites

  • Apple Silicon Device 🫠
  • MacOs 11 or later
  • A GitHub account

Homebrew

Homebrew calls itself The missing package manager for macOS and is an essential tool for any developer.

  1. Installation script

    Terminal window
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. The Homebrew installation script will ask you to enter your Mac user password. This is the password you used to sign into your Mac.

    Terminal window
    Password:

    You won’t see the characters as you type. Press enter when you are done.

  3. Option to install XCode Command Line Tools

    If you haven’t already installed XCode Command Line Tools, you’ll see a message that The XCode Command Line Tools will be installed.

    Press return to continue when prompted by the Homebrew installation script.

  4. Add to the $PATH shell configuration

    Homebrew files are installed into the /opt/homebrew folder. But the folder is not part of the default $PATH.

    Terminal window
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/ak/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"

    Be very careful to copy the commands exactly. It’s best to copy and paste.

  5. Update everything in Homebrew to recent version:

    Terminal window
    brew update
    brew outdated
    brew upgrade

Terminal

iTerm2 is an open source replacement for Apple’s Terminal. It’s highly customizable and comes with a lot of useful features.

Installation

Use Homebrew to download and install:

Terminal window
brew install --cask iterm2

Customization

Here are some suggested settings you can change or set, they are all optional.

  • Set hot-key to open and close the terminal to command + option + i

  • Go to profiles -> Default -> Terminal -> Check silence bell to disable the terminal session from making any sound

  • Download one of iTerm2 color schemes and then set these to your default profile colors

  • Change the cursor text and cursor color to yellow make it more visible

  • Change the font to 14pt Source Code Pro Lite. Source Code Pro can be downloaded using Homebrew

    Terminal window
    brew tap homebrew/cask-fonts && brew install --cask font-source-code-pro

Zsh

The Z shell (also known as zsh) is a Unix shell that is built on top of bash (the default shell for macOS) with additional features. It’s recommended to use zsh over bash. It’s also highly recommended to install a framework with zsh as it makes dealing with configuration, plugins and themes a lot nicer.

Installing Zsh

Install zsh using Homebrew:

Terminal window
brew install zsh

Now you should install a framework, we recommend to use OhMyZsh.

OhMyZsh

OhMyZsh is an open source, community-driven framework for managing your zsh configuration. It comes with a bunch of features out of the box and improves your terminal experience.

Installing OhMyZsh

Enter the following command into your terminal to install OhMyZsh:

Terminal window
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

The installation script should set zsh to your default shell, but if it doesn’t you can do it manually:

Terminal window
chsh -s $(which zsh)

Plugins

There are countless plugins available, but these two are recommend most.

zsh-autosuggestions

Autosuggestions for zsh, It suggests commands as you type based on history and completions.

  1. Clone this repository into $ZSH_CUSTOM/plugins (by default ~/.oh-my-zsh/custom/plugins)

    Terminal window
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  2. Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):

    Terminal window
    plugins=(git zsh-autosuggestions)
  3. Start a new terminal session.

zsh-syntax-highlighting

This package provides syntax highlighting for the shell zsh. It enables the highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.

  1. Clone this repository in oh-my-zsh’s plugins directory:

    Terminal window
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  2. Activate the plugin in ~/.zshrc:

    Terminal window
    plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
  3. Start a new terminal session.

    A huge list of plugins can be found at the awesome zsh plugins repo.

Git Config

Git should come pre-installed on mac, if not run:

Terminal window
brew install git

Name

To set up your Git config file, open a WSL command line and set your name with this command (replacing “Your Name” with your preferred username):

Terminal window
git config --global user.name "Your Name"

Email

Set your email with this command (replacing “[email protected]” with the email you prefer):

Terminal window
git config --global user.email "[email protected]"

Username

And finally, add your GitHub username to link it to git (case sensitive!):

Terminal window
git config --global user.username "GitHub username"

Make sure you are inputting user.username and not user.name otherwise, you will overwrite your name and you will not be correctly synced to your GitHub account.

You can double-check any of your settings by typing git config --global user.name and so on. To make any changes just type the necessary command again as in the examples above.

Python

This section covers setting up python environment for MacOS. Python is one of the most powerful programming languages, mostly used in data science, machine learning, and big data analytics.

Python Installation

Terminal window
brew install python

This will install the latest version of Python 3. You can verify the installation with:

Terminal window
python3 --version

Setting Up Your Python Environment

Once you’ve installed Python you might want to explore some additional tools that will make your Python development experience better. These tools help you manage different Python versions and keep your projects’ dependencies isolated.

Managing Multiple Python Versions with uv

If you work on different Python projects, you might find yourself needing different Python versions. This is where uv comes in handy. It’s a tool that allows you to install and switch between multiple Python versions effortlessly.

  1. Install uv using Homebrew:

    Terminal window
    brew install uv
  2. To enable shell autocompletion for uv, run this:

    Terminal window
    echo 'eval "$(uv generate-shell-completion zsh)"' >> ~/.zshrc
  3. To enable shell autocompletion for uvx, run this:

    Terminal window
    echo 'eval "$(uvx --generate-shell-completion zsh)"' >> ~/.zshrc

    Then restart the shell or source the shell config file.

  4. Install the Python version you need:

    Terminal window
    uv python install 3.10.x

Working with Virtual Environments

Virtual environments are an essential tool for modern Python development. They create isolated spaces where you can install packages without affecting your system-wide Python installation. This prevents dependency conflicts between different projects.

  1. Create a new environment using uv:

    Terminal window
    uv venv
  2. Install a package in the new virtual environment

    Terminal window
    uv pip install ruff
  3. The virtual environment can be “activated” to make its packages available:

    Terminal window
    source .venv/bin/activate
  4. When you’re done, deactivate the environment:

    Terminal window
    deactivate

Docker

This section covers setting docker desktop for MacOS. In the end, you will have a docker-daemon, docker-cli, docker-compose, and more.

Docker provides the ability to package and run an application in a loosely isolated environment called a container. For more info Checkout Docs.

Docker Installation

  1. Download the executable for docker-desktop.

  2. Install the executable, and choose the appropriate virtualization environment while installing if the option shows up.

  3. Done with installation. Sign in with the docker account or skip for the time being.

Test Docker CLI

Make sure you at least launch docker-desktop once, and let it run in the background.

Terminal window
docker -v

You have successfully installed docker-desktop and all other necessary tools docker-cli, docker-compose, and more.

Package Managers

JavaScript package managers play a pivotal role in web development. They are tools that automate installing, upgrading, configuring, and consistently removing computer programs. They are critical in managing the numerous packages developers use to build complex applications.

Three prominent package managers have gained popularity in the JavaScript community: NPM, Yarn, PNPM and Bun.

NPM

  • As the name suggests, NPM (Node Package Manager) is a package manager for the JavaScript runtime environment Node.js.

  • It comes bundled with Node.js, so when you install Node.js, you automatically get NPM installed on your computer.

YARN

  • Yarn is a new package manager developed by Facebook in response to some of the problems they faced with NPM, particularly regarding speed, security, and reliability.

  • Yarn introduced some new features unavailable in NPM, such as offline package installation and deterministic dependency resolution.

  • Installation

    Terminal window
    brew install yarn

PNPM

  • PNPM, standing for Performant NPM, is a JavaScript package manager that aims to solve some of the issues associated with NPM and Yarn.

  • It can be a drop-in replacement for these tools while providing better performance and disk space usage.

  • PNPM uses a unique approach to manage node modules, which makes it highly disk efficient.

  • Installation

    Terminal window
    brew install pnpm

Bun

  • Bun is an all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.

  • It aims to provide a high-performance alternative to Node.js with better speed and resource efficiency.

  • Bun’s package manager is significantly faster than npm, yarn, and pnpm while maintaining compatibility with the npm registry.

  • Installation

    Terminal window
    curl -fsSL https://bun.sh/install | bash

Basic commands

  1. Initialize a new project

    To create a new project, navigate to your project directory and run the following commands.

    Terminal window
    bun init -y

    This will create a package.json file with the default settings.

  2. Install a package

    To install the required package, you can run the following commands.

    Terminal window
    bun add <package-name>

    This will install and add the package to your package.json file under the dependencies section.

  3. Install a development package

    To install a package for development purposes, run the following commands.

    Terminal window
    bun add -D <package-name>

    This will install and add the package to your package.json file under the devDependencies section.

  4. Run a script

    To run a script defined in your package.json file, run the following commands

    Terminal window
    bun run <script-name>

    This will run the script defined in the scripts section of your package.json file.

Integrated Development Environment

  • Essentially, there are two different philosophies that define your setup as a web developer.

  • While there are developers who prefer to have all their tooling in one Integrated Development Environment (IDE), there are developers who prefer to use multiple lightweight tools (e.g. editor/IDE, standalone terminal) and combine them for their purposes.

  • For beginners to web development, we recommend using one tool. The IDE (e.g. VS Code) combines everything that is needed for coding (editor) and executing the code (integrated terminal).

Installing VS Code

To install the latest version, use Homebrew:

Terminal window
brew install --cask visual-studio-code

MacOs integration

Launch VS Code from the command line.

After that, you can launch VS Code from your terminal:

  • code . will open VS Code in the current directory
  • code myfile.txt will open myfile.txt in VS Code

Useful Extensions

  • Python - Includes many useful features, such as code completion with IntelliSense, debugging, unit testing support, etc.

  • Docker - Makes it easy to create, manage, and debug containerized applications.

  • Error Lens - Improve highlighting of errors, warnings and other language diagnostics.

  • indent-rainbow - Makes indentation easier to read.

  • MDX - Language support for MDX

  • vscode-icons - Icons for Visual Studio Code

  • Fluent Icons - Fluent product icons for Visual Studio Code

  • Material Theme Icons - Material Theme Icons, the most epic icons theme for Visual Studio Code and Material Theme.

References

Start your journey with ChaiCode

All of our courses are available on chaicode.com. Feel free to check them out.