Setting Develop Environment for Mac with Homebrew

3 minute read

Written by SGLee, VCANUS

Basic Tools

XCode

install XCode

install Xcode on App Store The below is not needed if command line tools are already installed.

install XCode Command Line Tools

$ xcode-select --install

install XCode in App Store

Homebrew

install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

add path to .zshrc

terminal에서 해당 폴더 찾아서 확인 후 HOMEBREW_HOME 추가

# for arm chip
export HOMEBREW_HOME="/opt/homebrew"
# for intel chip
#export HOMEBREW_HOME="/usr/local/Homebrew"
export PATH="$HOMEBREW_HOME/bin:$PATH"
export PATH="$HOMEBREW_HOME/sbin:$PATH"

현재 사용 중인 .zshrc

# for arm chip
export HOMEBREW_HOME="/opt/homebrew"
# for intel chip
#export HOMEBREW_HOME="/usr/local/Homebrew"

# jenv config
export PATH="$HOME/.jenv/bin:$PATH"

#export ANDROID_HOME="/Users/sglee/Library/Android/sdk"

export PATH="$HOMEBREW_HOME/bin:$PATH"
export PATH="$HOMEBREW_HOME/sbin:$PATH"
export PATH="$JAVA_HOME/bin:$PATH"
export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$HOMEBREW_HOME/opt/curl/bin:$PATH"
#export PATH="ANDROID_HOME:$PATH"
#export PATH="/Users/sglee/Library/Python/3.8/bin:$PATH"
#export PATH="/Users/sglee/virtualenvs/jupyter/bin:$PATH"
#export PATH="/Applications/CMake.app/Contents/bin:$PATH"

# poetry
#export PATH="/Users/sglee/Library/Application\ Support/pypoetry/venv/bin:$PATH"

## essential for x86 mac
#export CPLUS_INCLUDE_PATH="/usr/local/include"
#export LIBRARY_PATH="/usr/local/lib"

# essential for arm mac
export CPLUS_INCLUDE_PATH="/opt/homebrew/include"
export LIBRARY_PATH="/opt/homebrew/lib"

# for android development
#export PATH=$PATH:$ANDROID_HOME/emulator
#export PATH=$PATH:$ANDROID_HOME/tools
#export PATH=$PATH:$ANDROID_HOME/tools/bin
#export PATH=$PATH:$ANDROID_HOME/platform-tools


eval "$(jenv init -)"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/sglee/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/sglee/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/sglee/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/sglee/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

# The following lines have been added by Docker Desktop to enable Docker CLI completions.
fpath=(/Users/sglee/.docker/completions $fpath)
autoload -Uz compinit
compinit
# End of Docker CLI completions

.zshrc 적용

cd
source .zshrc

update homebrew

$brew update

Rosetta 2

  • Intel chip용으로 개발된 App을 Arm chip (M1, M2…) Mac에서 실행하기 위함
  • 구형 App을 구동하기 위함이 아니면 설치 의미 없을 듯 (Pytorch 초기 버전에서 M1 chip을 지원하기 위해 Rosetta 설치가 필요한 적이 있었음)
    sudo softwareupdate --install-rosetta
    

Java

AdoptOpenJdk: Deprecated

Install Temurin (https://adoptium.net/installation/)

brew install --cask temurin@8
brew install --cask temurin@11
brew install --cask temurin@17
brew install --cask temurin@21

jenv (java version switching tool)

install

brew install jenv

update .zshrc

# jenv config
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

register jdk path to jenv

jenv add /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home

check installed java version

jenv versions

set default java version

설치된 java 버전 확인 후 설정

jenv global temurin64-17.0.16

enable jenv plugin

jenv enable-plugin export

Essential libraries

install cmake, curl, maven, openssl, etc.

install cmake

$ brew install cmake

install curl, zlib

boost나 opencv 설치 시 기본적으로 필요함

$ brew install curl
$ brew install zlib

install maven (필요 시 설치)

$ brew install maven

install openssl (참고만 하고 설치하지 말 것)

$ brew install openssl
==> intel chip
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
==> M1 chip
openssl@1.1 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

Python

  • 가상환경: conda 사용
  • 패키지 관리: poetry 사용
  • python 버전은 가상 환경에서 관리 (homebrew로 전역으로 사용하는 python 설치하지 말 것)
  • Target: Pytorch, OpenCV, Tensorflow
    https://developer.apple.com/metal/pytorch/ https://pytorch.org/get-started/locally/#mac-python

    Conda

    https://angel-breath.tistory.com/29

    install miniconda

  • download: https://www.anaconda.com/download/success
  • sh 파일 다운로드 후 설치
    $chomod +x <file>
    $sh <file>
    

    usage

    create env

    conda create -n {env-name} python={version}
    

    remove env

    conda env remove -n {env-name}
    

    search env list

    conda env list
    

    activate/deactivate

    conda activate {env-name}
    conda deactivate
    

    PyCharm에서 활용

    conda env 생성

    python 버전 설정으로 동일 환경 유지

    conda create -n flowbroker python=3.11
    

    PyCharm 설정

    Settings > Projejct > Python Interpreter > Add Interpreter > Conda Environment > Use Existing Environment

    PyCharm 프로젝트 내 패키지 설치

    github repository

    poetry로 설치, poetry add

    poetry add numpy
    

    pip로 설치 (github 연동 패키지 설치)

    pip install git+https://github.com/vcanus/vpy-util.git@develop
    pip install git+https://github.com/vcanus/vpy-communication-api.git@develop
    
    일반 패키지

    가상 환경 내 설치 => poetry 사용 권장

    conda install <package>
    poetry add <package>
    

Jupyter

install Jupyter notebook

https://jupyter.org/install https://towardsdatascience.com/how-to-set-up-anaconda-and-jupyter-notebook-the-right-way-de3b7623ea4a https://bbooo.tistory.com/25

conda install -c conda-forge jupyterlab
conda install -c conda-forge nb_conda_kernels

install libraries

conda activate {conda-env}
conda install ipykernel

run Jupyter

jupyter lab # run jupyter notebook

Etc. libraries

brew install hiredis
brew install boost
brew search google
brew install googletest
brew install protobuf protobuf-c
brew install cnats
brew install protobuf protobuf-c
brew install --cask flutter

Leave a comment