修改Terminal中@后的名字

  • 修改计算机名 ComputerName

    1. 修改

      1
      scutil --set ComputerName "New ComputerName"
    2. 重启mac

    3. 查看

      1
      scutil --get ComputerName
  • 修改主机名 HostName

    1. 修改

      1
      scutil --set HostName "New HostName"
    2. 重启mac

    3. 查看

      1
      scutil --get HostName
  • 修改本地主机名 LocalHostName

    1. 修改

      1
      scutil --set LocalHostName  "New HostName"
    2. 重启mac

    3. 查看

      1
      scutil --get LocalHostName

开盖开机设置

  • Intel 芯片

    • 禁用开盖开机

      1
      sudo nvram AutoBoot=%00
    • 恢复默认设置

      1
      sudo nvram AutoBoot=%03
  • Apple Silicon 芯片

    • 同时禁用开盖和插入电源时的系统自启动

      1
      sudo nvram BootPreference=%00
    • 只禁用开盖自动启动

      1
      sudo nvram BootPreference=%01
    • 只禁用插入电源时的自动启动

      1
      sudo nvram BootPreference=%02
    • 恢复默认设置

      1
      sudo nvram -d BootPreference

Homebrew

  1. 官网 : https://brew.sh/zh-cn/

  2. 运行命令

    • 官网安装源

      1
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • 国内安装源

      1
      /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

oh-my-zsh

  • 切换zsh为默认shell

  • 安装oh-my-zsh

    1. 官网 : https://ohmyz.sh/

    2. 安装

      • 自动安装
      1
      sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
      • 手动安装

        1. 从git克隆

          1
          git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
        2. 从template模板创建配置文件

          1
          cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
    3. 重启终端或者执行source ~/.zshrc命令

  • 切换主题

    • 修改~/.zshrc文件内 ZSH_THEME 行

      1
      2
      3
      4
      # 单个主题
      ZSH_THEME=“theme”
      # 多个主题随机
      ZSH_THEME_RANDOM_CANDIDATES=( "theme1" "theme2" "theme3" )

      主题文件在 ~/.oh-my-zsh/themes 目录下

      主题预览 : https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

  • 插件安装

    • zsh-completions

      • 简介 : 额外的自动补全功能

      • 地址 : https://github.com/zsh-users/zsh-completions

      • 安装

        使用homebrew进行安装

        1
        brew install zsh-completions

        根据控制台输出的提示,修改~/.zshrc文件在最后添加

        1
        2
        3
        4
        5
        6
        7
        8
        # 插件 额外的自动补全功能 start ============================================
        if type brew &>/dev/null; then
        FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

        autoload -Uz compinit
        compinit
        fi
        # 插件 额外的自动补全功能 end ============================================

        重启终端或者执行source ~/.zshrc命令

    • zsh-autosuggestions

      • 简介 : 历史命令记录提示(灰色), 按 → 键补全

      • 地址 : https://github.com/zsh-users/zsh-autosuggestions

      • 安装

        执行命令

        1
        git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-autosuggestions

        修改~/.zshrc文件plugins=(行后 添加 zsh-autosuggestions

        1
        2
        3
        4
        5
        6
        plugins=(
        git
        xxxxxxxx
        # 历史命令记录提示
        zsh-syntax-highlighting
        )

        重启终端或者执行source ~/.zshrc命令

    • zsh-syntax-highlighting

      • 简介 : 语法高亮插件 红色: 语法错误; 绿色: 语法正确; 下划线: 路径存在

      • 地址 : https://github.com/zsh-users/zsh-syntax-highlighting

      • 安装

        执行命令

        1
        git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

        修改~/.zshrc文件plugins=(行后 添加 zsh-syntax-highlighting

        1
        2
        3
        4
        5
        6
        plugins=(
        git
        xxxxxxxx
        # 语法高亮插件
        zsh-syntax-highlighting
        )

        重启终端或者执行source ~/.zshrc命令

java

  1. 下载地址 : https://www.oracle.com/cn/java/technologies/downloads/

  2. 多版本切换配置

    • jdk默认安装目录 : /Library/Java/JavaVirtualMachines/

    • 修改

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      # java profile start ============================================
      export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
      export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
      export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
      export JAVA_17_HOME=$(/usr/libexec/java_home -v17)
      export JAVA_21_HOME=$(/usr/libexec/java_home -v21)


      alias jdk7='export JAVA_HOME=$JAVA_7_HOME'
      alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
      alias jdk11='export JAVA_HOME=$JAVA_11_HOME'
      alias jdk17='export JAVA_HOME=$JAVA_17_HOME'
      alias jdk21='export JAVA_HOME=$JAVA_21_HOME'
      alias jdk23='export JAVA_HOME=$JAVA_23_HOME'


      # 默认java版本
      export JAVA_HOME=$JAVA_8_HOME
      export PATH=$JAVA_HOME/bin:$PATH:.
      # export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH:.
      # java profile end ============================================
    • 重新加载配置

      1
      source ~/.zshrc
    • 检查

      • 查看JAVA_HOME

        1
        echo $JAVA_HOME
      • 查看java版本

        1
        java -version 
    • 切换命令

      1
      jdk8

maven

  1. 下载地址 : https://archive.apache.org/dist/maven/

  2. 解压到目录 ~/environment/apache/maven

  3. 编辑~/.zshrc文件

    1
    2
    3
    export MAVEN_HOME=~/environment/apache/maven/apache-maven-3.9.9
    export M2_HOME=~/environment/apache/maven/apache-maven-3.9.9
    export PATH=$MAVEN_HOME/bin:$PATH:.
  4. 配置maven, 修改settings.xml文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    <?xml version="1.0" encoding="UTF-8"?>

    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">

    <!-- 本地仓库 -->
    <localRepository>/Users/naclo/environment/apache/maven/maven-repositry</localRepository>

    <pluginGroups></pluginGroups>

    <proxies></proxies>

    <servers></servers>

    <mirrors>

    <!-- 阿里云仓库 -->
    <mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
    </mirror>

    <mirror>
    <id>maven-default-http-blocker</id>
    <mirrorOf>external:http:*</mirrorOf>
    <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
    <url>http://0.0.0.0/</url>
    <blocked>true</blocked>
    </mirror>
    </mirrors>

    <profiles>
    <!-- java版本 -->
    <profile>
    <id>jdk-1.8</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>
    </activation>

    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
    </profile>
    </profiles>

    </settings>
  5. 运行测试命令

    1
    2
    mvn -v
    mvn help:system

nvm

  1. 使用brew安装

    1
    brew install nvm