美文网首页
MacOS环境配置

MacOS环境配置

作者: JustinZhang_ | 来源:发表于2023-02-15 21:29 被阅读0次

    0. 代理

    • 为终端设置临时代理
    export ALL_PROXY="socks5://127.0.0.1:7890"
    # 测试
    curl www.google.com
    

    1. Homebrew

    名称 说明
    brew Homebrew源代码仓库
    homebrew-core Homebrew核心软件仓库
    homebrew-bottles Homebrew预编译二进制软件包
    homebrew-cask 提供macOS应用和大型二进制文件
    • 以下步骤使用国内镜像,无需代理
    # 设置环境变量
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
    export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
    export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
    # 拉取脚本运行
    /bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/HEAD/install.sh)"
    
    • 配置环境变量&软件源
    # Homebrew
    eval "$(/opt/homebrew/bin/brew shellenv)"
    # Set PATH, MANPATH, etc., for Homebrew.
    export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
    export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
    export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
    export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
    

    2. zsh

    • 默认没有.zshrc文件,需要自己手动创建
    • 默认不支持ll命令,需要自行配置(配置完oh my zsh后不需要以下配置)
    # Keys
    alias ll='ls -l'
    alias lla='ls -al'
    
    # 拉取脚本执行
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    # 之前配置的环境变量.zshrc文件会被重命名为.zshrc.pre-oh-my-zsh
    # 可将其重命名为.profile,并在当前.zshrc中激活
    
    • 设置oh-my-zsh主题
    # 修改.zshrc文件
    vim .zshrc
    # 设置为agnoster主题
    ZSH_THEME="agnoster"
    
    # clone
    git clone https://github.com/powerline/fonts.git --depth=1
    # install
    cd fonts
    ./install.sh
    # clean-up a bit
    cd ..
    rm -rf fonts
    
    • 安装zsh插件
    # 提示插件,(https://github.com/zsh-users/zsh-autosuggestions)
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    # 高亮插件,(https://github.com/zsh-users/zsh-syntax-highlighting)
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    # 配置插件
    vim ~/.zshrc
    plugins=(
        git
        zsh-autosuggestions
        zsh-syntax-highlighting
    )
    
    • 设置显示当前路径
    # 编辑oh-my-zsh当前使用的主题
    # 找到prompt_dir()方法
    prompt_dir() {
      prompt_segment blue $CURRENT_FG '%~' # 修改前
      prompt_segment blue $CURRENT_FG '%1~' # 修改后
    }
    

    3. git

    • 安装完Homebrew后,会因为Xcode自动安装git,无法卸载,忽略即可
    • 使用brew安装git
    # 安装git
    brew install git
    # 配置环境变量
    vim ~/.zshrc
    # 添加内容
    # Git
    export GIT_HOME=/opt/homebrew/Cellar/git/2.39.1
    export PATH=$GIT_HOME/bin:$PATH
    # 激活
    source ~/.zshrc
    

    4. iTerm2

    • 支持多窗口,可以使用其替换默认的Terminal

    5. JDK&Maven

    # Java
    export JAVA_HOME=/Users/justin/Env/zulu8u362
    export CLASSPATH=.:$JAVA_HOME/lib
    export PATH=$JAVA_HOME/bin:$PATH
    
    # Maven
    export MAVEN_HOME=/Users/justin/Env/apache-maven-3.9.0
    export PATH=$MAVEN_HOME/bin:$PATH
    

    6. NVM&Node&NPM

    • NVM
    # 拉取脚本执行
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    # 配置环境变量
    # 默认配置在.zshrc中,可以将其移动到.profile
    # NVM
    export NVM_DIR="$HOME/.nvm"
    # This loads nvm
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    # This loads nvm bash_completion
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
    
    • Node源
    # Node Mirror
    export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/
    
    • 安装Node
    nvm ls-remote
    nvm install xxx
    nvm use xxx
    
    • NPM源
    npm config set registry https://registry.npmmirror.com
    

    7. Docker Desktop

    • 安装rosetta2
    • softwareupdate --install-rosetta
    • 下载Docker Desktop安装包Apple Chip

    相关文章

      网友评论

          本文标题:MacOS环境配置

          本文链接:https://www.haomeiwen.com/subject/ovpukdtx.html