一、安装homebrew
Homebrew是macOS和Linux平台上的包管理工具,它紧张用于简化软件的安装、更新和卸载过程。安装了Homebrew后,安装&更新&卸载软件只必要一行下令就可以。
homebrew常用下令
官网:Homebrew — The Missing Package Manager for macOS (or Linux)
官方安装脚本(不推荐)
国内使用官方安装脚本会比较慢,1小时都未必能安装好,不推荐。
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
复制代码 国内镜像安装(推荐)
- 安装:
- /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
- 卸载:
- /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
复制代码 设置情况变量
在安装完成后假如遇到command not found: brew的错误,一般是情况变量无效,遇到这种情况举行以下操作:
使用echo $SHELL来确认终端范例,如下:
早期默认shell是/bin/bash,则设置文件为~/.bash_profile。从macOS Catalina(10.15.x) 版开始,Mac使用/bin/zsh作为默认Shell,设置文件为~/.zshrc。
确认Mac电脑CPU型号
M1芯片ARM版Homebrew终极会被安装在/opt/homebrew路径下,而之前Intel芯片的Mac则会被安装到/usr/local/Homebrew路径下。我们在设置Homebrew情况变量的时候,必要联合不同的情况来举行相应的设置,如下:
M1芯片
- echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
- eval "$(/opt/homebrew/bin/brew shellenv)"
- echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
- eval "$(/opt/homebrew/bin/brew shellenv)"
复制代码 Intel芯片
- echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)"' >> ~/.zprofile
- eval "$(/usr/local/Homebrew/bin/brew shellenv)"
- echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)"' >> ~/.bash_profile
- eval "$(/usr/local/Homebrew/bin/brew shellenv)"
复制代码 更换镜像源
Homebrew采用默认镜像源下载软件时非常慢。为了提升下载速率,必要更改Homebrew的安装源,将其替换成国内镜像。
1. 检察当前镜像源
- 1.查看 brew.git 镜像源
- cd "$(brew --repo homebrew/core)" && git remote -v
- 结果:
- origin https://github.com/Homebrew/brew.git (fetch)
- origin https://github.com/Homebrew/brew.git (push)
- 2.查看 homebrew-core.git 镜像源
- cd "$(brew --repo homebrew/core)" && git remote -v
- 结果:
- origin https://github.com/Homebrew/homebrew-core.git (fetch)
- origin https://github.com/Homebrew/homebrew-core.git (push)
复制代码 2. 更换为国内镜像源_阿里云(推荐)
- 1.替换brew.git:
- cd "$(brew --repo)" && git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
- 2.替换homebrew-core.git:
- cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
- && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
- 3.替换homebrew-cask.git:
- cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
- && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
复制代码 其它的镜像源:
- 注意:不同镜像源域名
- git:
- https://github.com/Homebrew/brew.git
- https://github.com/Homebrew/homebrew-core.git
- 华中科大:
- https://mirrors.ustc.edu.cn/brew.git
- https://mirrors.ustc.edu.cn/homebrew-core.git
- 阿里云:
- https://mirrors.aliyun.com/homebrew/brew.git
- https://mirrors.aliyun.com/homebrew/homebrew-core.git
- 阿里云的镜像云注意域名后多了一个"homebrew"
- 腾讯:
- https://mirrors.cloud.tencent.com/homebrew/brew.git
- https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git
复制代码 重置为官方镜像源
假如要重置官方源,实行以下下令:
- 1.重置 brew.git 为官方源:
- cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew.git
- 2.重置 homebrew-core.git 为官方源:
- cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://github.com/Homebrew/homebrew-core.git
- 3.重置 homebrew-cask.git 为官方源:
- cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
- && git remote set-url origin https://github.com/Homebrew/homebrew-cask
- 4.zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置,前面加#符号就行
- vi ~/.zshrc
- # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
- 5.修改使其立即生效
- source ~/.zshrc
- 6.刷新源
- brew update
复制代码
二、安装设置Git
安装git
安装完成检查是否安装乐成
设置git排除.DS_Store文件版本管理
- 将.DS_Store加入全局的·gitignore文件,实行下令:
- echo .DS_Store >>~/.gitignore_global
复制代码
- 将这个全局的.gitignore文件加入Git的全局config文件中,实行下令:
- git config --global core.excludesfile ~/.gitignore_global
复制代码 哦了.DS Store再也不会出现在你项目的Git代码仓库中了!
三、安装jdk,设置情况变量
1、安装jdk,版本依据本身必要自选
安装完成后实行以下下令,让系统可以链接找到java。
- sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
复制代码 2、检查是否安装乐成
打开终端,输入下令java -version,假如显示信息表明安装乐成。
- java -version
- 结果:
- openjdk version "11.0.24" 2024-07-16
- OpenJDK Runtime Environment Homebrew (build 11.0.24+0)
- OpenJDK 64-Bit Server VM Homebrew (build 11.0.24+0, mixed mode)
复制代码 3、设置情况变量
- 1.查看你jdk安装的路径:
- /usr/libexec/java_home -V
- 2.打开当前用户home目录:
- cd ~/
- 3.使用touch .bash_profile创建一个.bash_profile的隐藏配置文件。使用命令open -e .bash_profile编辑内容
- touch .bash_profile
- open -e .bash_profile
- 内容为(homebrew 安装jdk的目录):
- export JAVA_HOME=/opt/homebrew/opt/openjdk@11
- Command +S保存.bash_profile文件
- 4.使用source ~/.bash_profile命令,使配置生效
- source ~/.bash_profile
- 5.使用echo $JAVA_HOME命令。命令显示刚才配置的路径,返回的信息对应上了上面的路径就说明配置成功了。
- echo $JAVA_HOME
复制代码
四、安装maven及设置
1、安装maven
直接实行brew install maven会耗费很长时间,而且大概率会失败。
由于maven安装会依赖很多组件,好比openidk,直接安装很有大概由于下载超时失败,因此在安装好jdk,git后仅需安装maven即可,不要按装额外的依赖组件。
因此使用--ignore-dependencies制止下载依赖组件会很快。
- brew install --ignore-dependencies maven
复制代码 默认安装在 /opt/homebrew/Cellar/maven/ 目次
假如要指定安装目次,可以使用如下下令:
- brew install maven --prefix=[installation path]
复制代码 [installation pathl是要安装的目次路径
2、情况变量设置
- 1.使用命令open -e .bash_profile编辑内容
- touch .bash_profile
- open -e .bash_profile
- 追加内容(homebrew 安装maven的目录):
- export MAVEN_HOME=/opt/homebrew/Cellar/maven/3.9.9/libexec
- export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
- Command +S保存.bash_profile文件
- 2.使用source ~/.bash_profile命令,使配置生效
- source ~/.bash_profile
- 3.使用echo $MAVEN_HOME命令。命令显示刚才配置的路径,返回的信息对应上了上面的路径就说明配置成功了。
- echo $MAVEN_HOME
复制代码 3、设置当地仓库
找到maven安装目次下/conf文件夹
我本机是/opt/homebrew/Cellar/maven/3.9.9/libexec/conf
打开文件设置maven仓库open -e settings.xml
- <!--本地仓库目录-->
- <localRepository>/Users/userxxx/.m2/repository</localRepository>
- <!--配置server,具体需依据公司仓库服务具体值配置-->
- <servers>
- <server>
- <id>deploymentRepo</id>
- <username>repouser</username>
- <password>repopwd</password>
- </server>
- </servers>
- <!--配置远程中央仓库,例子中是阿里云公共仓库,具体需依据公司仓库服务具体值配置-->
- <mirrors>
- <mirror>
- <id>aliyunmaven</id>
- <mirrorOf>*</mirrorOf>
- <name>阿里云公共仓库</name>
- <url>https://maven.aliyun.com/repository/public</url>
- </mirror>
- </mirrors>
- <!--配置maven插件-->
- <profiles>
- <profile>
- <id>jdk-11</id>
- <activation>
- <jdk>11.0.24</jdk>
- </activation>
- <repositories>
- <repository>
- <id>central</id>
- <url>https://maven.aliyun.com/repository/central</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- </repository>
- </repositories>
- </profile>
- </profiles>
- <!--配置其它-->
- <pluginGroups>
- <pluginGroup>com.alibaba.org.apache.maven.plugins</pluginGroup>
- <pluginGroup>com.alibaba.maven.plugins</pluginGroup>
- </pluginGroups>
- <activeProfiles>
- <activeProfile>nexus</activeProfile>
- </activeProfiles>
复制代码 五、idea设置
JDK设置
点击菜单栏中的“File”选项。选择“Project Structure”以打开项目布局设置窗口。
maven设置
idea假如不设置,默认是使用idea内置的maven,而非homebrew安装的maven。
打开IntelliJIDEA--> references...-->Build,Execution,Deployment-->Build Tools-->Maven
修改Maven home path选项,如下图:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |