Mac安装设置Java,Git,Maven情况大全

打印 上一主题 下一主题

主题 995|帖子 995|积分 2985

一、安装homebrew

Homebrew是macOS和Linux平台上的包管理工具,它紧张用于简化软件的安装、更新和卸载过程。安装了Homebrew后,安装&更新&卸载软件只必要一行下令就可以。
homebrew常用下令
官网:Homebrew — The Missing Package Manager for macOS (or Linux)
官方安装脚本(不推荐)

国内使用官方安装脚本会比较慢,1小时都未必能安装好,不推荐。  
  1. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
复制代码
国内镜像安装(推荐)

  1. 安装:
  2. /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
  3. 卸载:
  4. /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
复制代码
设置情况变量

在安装完成后假如遇到command not found: brew的错误,一般是情况变量无效,遇到这种情况举行以下操作:
使用echo $SHELL来确认终端范例,如下:
  1. echo $SHELL
复制代码
早期默认shell是/bin/bash,则设置文件为~/.bash_profile。从macOS Catalina(10.15.x) 版开始,Mac使用/bin/zsh作为默认Shell,设置文件为~/.zshrc。
确认Mac电脑CPU型号
  1. uname -m
复制代码
M1芯片ARM版Homebrew终极会被安装在/opt/homebrew路径下,而之前Intel芯片的Mac则会被安装到/usr/local/Homebrew路径下。我们在设置Homebrew情况变量的时候,必要联合不同的情况来举行相应的设置,如下:
M1芯片
  1. echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
  2. eval "$(/opt/homebrew/bin/brew shellenv)"
  3. echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
  4. eval "$(/opt/homebrew/bin/brew shellenv)"
复制代码
Intel芯片
  1. echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)"' >> ~/.zprofile
  2. eval "$(/usr/local/Homebrew/bin/brew shellenv)"
  3. echo 'eval "$(/usr/local/Homebrew/bin/brew shellenv)"' >> ~/.bash_profile
  4. eval "$(/usr/local/Homebrew/bin/brew shellenv)"
复制代码
更换镜像源

Homebrew采用默认镜像源下载软件时非常慢。为了提升下载速率,必要更改Homebrew的安装源,将其替换成国内镜像。
1. 检察当前镜像源

  1. 1.查看 brew.git 镜像源
  2. cd "$(brew --repo homebrew/core)" && git remote -v
  3. 结果:
  4. origin    https://github.com/Homebrew/brew.git (fetch)
  5. origin    https://github.com/Homebrew/brew.git (push)
  6. 2.查看 homebrew-core.git 镜像源
  7. cd "$(brew --repo homebrew/core)" && git remote -v
  8. 结果:
  9. origin    https://github.com/Homebrew/homebrew-core.git (fetch)
  10. origin    https://github.com/Homebrew/homebrew-core.git (push)
复制代码
2. 更换为国内镜像源_阿里云(推荐)

  1. 1.替换brew.git:
  2. cd "$(brew --repo)" && git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
  3. 2.替换homebrew-core.git:
  4. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
  5. && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
  6. 3.替换homebrew-cask.git:
  7. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
  8. && git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-cask.git
复制代码
其它的镜像源:
  1. 注意:不同镜像源域名
  2. git:
  3. https://github.com/Homebrew/brew.git
  4. https://github.com/Homebrew/homebrew-core.git
  5. 华中科大:
  6. https://mirrors.ustc.edu.cn/brew.git
  7. https://mirrors.ustc.edu.cn/homebrew-core.git
  8. 阿里云:
  9. https://mirrors.aliyun.com/homebrew/brew.git
  10. https://mirrors.aliyun.com/homebrew/homebrew-core.git
  11. 阿里云的镜像云注意域名后多了一个"homebrew"
  12. 腾讯:
  13. https://mirrors.cloud.tencent.com/homebrew/brew.git
  14. https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git
复制代码
重置为官方镜像源

假如要重置官方源,实行以下下令:
  1. 1.重置 brew.git 为官方源:
  2. cd "$(brew --repo)" && git remote set-url origin https://github.com/Homebrew/brew.git
  3. 2.重置 homebrew-core.git 为官方源:
  4. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" && git remote set-url origin https://github.com/Homebrew/homebrew-core.git
  5. 3.重置 homebrew-cask.git 为官方源:
  6. cd "$(brew --repo)/Library/Taps/homebrew/homebrew-cask"
  7. && git remote set-url origin https://github.com/Homebrew/homebrew-cask
  8. 4.zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置,前面加#符号就行
  9. vi ~/.zshrc
  10. # export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
  11. 5.修改使其立即生效
  12. source ~/.zshrc
  13. 6.刷新源
  14. brew update
复制代码

二、安装设置Git

安装git
  1. brew install git
复制代码
安装完成检查是否安装乐成
  1. git -v
复制代码
设置git排除.DS_Store文件版本管理


  • 将.DS_Store加入全局的·gitignore文件,实行下令:
  1. echo .DS_Store >>~/.gitignore_global
复制代码


  • 将这个全局的.gitignore文件加入Git的全局config文件中,实行下令:
  1. git config --global core.excludesfile ~/.gitignore_global
复制代码
哦了.DS Store再也不会出现在你项目的Git代码仓库中了!

三、安装jdk,设置情况变量

1、安装jdk,版本依据本身必要自选

  1. brew install openjdk@11
复制代码
安装完成后实行以下下令,让系统可以链接找到java。
  1. sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
复制代码
2、检查是否安装乐成

打开终端,输入下令java -version,假如显示信息表明安装乐成。
  1. java -version
  2. 结果:
  3. openjdk version "11.0.24" 2024-07-16
  4. OpenJDK Runtime Environment Homebrew (build 11.0.24+0)
  5. OpenJDK 64-Bit Server VM Homebrew (build 11.0.24+0, mixed mode)
复制代码
3、设置情况变量

  1. 1.查看你jdk安装的路径:
  2. /usr/libexec/java_home -V
  3. 2.打开当前用户home目录:
  4. cd ~/
  5. 3.使用touch .bash_profile创建一个.bash_profile的隐藏配置文件。使用命令open -e .bash_profile编辑内容
  6. touch .bash_profile
  7. open -e .bash_profile
  8. 内容为(homebrew 安装jdk的目录):
  9. export JAVA_HOME=/opt/homebrew/opt/openjdk@11
  10. Command +S保存.bash_profile文件
  11. 4.使用source ~/.bash_profile命令,使配置生效
  12. source ~/.bash_profile
  13. 5.使用echo $JAVA_HOME命令。命令显示刚才配置的路径,返回的信息对应上了上面的路径就说明配置成功了。
  14. echo $JAVA_HOME
复制代码

四、安装maven及设置

1、安装maven

直接实行brew install maven会耗费很长时间,而且大概率会失败。
由于maven安装会依赖很多组件,好比openidk,直接安装很有大概由于下载超时失败,因此在安装好jdk,git后仅需安装maven即可,不要按装额外的依赖组件。
因此使用--ignore-dependencies制止下载依赖组件会很快。
  1. brew install --ignore-dependencies maven
复制代码
默认安装在 /opt/homebrew/Cellar/maven/ 目次
假如要指定安装目次,可以使用如下下令:
  1. brew install maven --prefix=[installation path]
复制代码
[installation pathl是要安装的目次路径
2、情况变量设置

  1. 1.使用命令open -e .bash_profile编辑内容
  2. touch .bash_profile
  3. open -e .bash_profile
  4. 追加内容(homebrew 安装maven的目录):
  5. export MAVEN_HOME=/opt/homebrew/Cellar/maven/3.9.9/libexec
  6. export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
  7. Command +S保存.bash_profile文件
  8. 2.使用source ~/.bash_profile命令,使配置生效
  9. source ~/.bash_profile
  10. 3.使用echo $MAVEN_HOME命令。命令显示刚才配置的路径,返回的信息对应上了上面的路径就说明配置成功了。
  11. echo $MAVEN_HOME
复制代码
3、设置当地仓库

找到maven安装目次下/conf文件夹
我本机是/opt/homebrew/Cellar/maven/3.9.9/libexec/conf
打开文件设置maven仓库open -e settings.xml
  1. <!--本地仓库目录-->
  2. <localRepository>/Users/userxxx/.m2/repository</localRepository>
  3. <!--配置server,具体需依据公司仓库服务具体值配置-->
  4. <servers>
  5.     <server>
  6.       <id>deploymentRepo</id>
  7.       <username>repouser</username>
  8.       <password>repopwd</password>
  9.     </server>
  10. </servers>
  11. <!--配置远程中央仓库,例子中是阿里云公共仓库,具体需依据公司仓库服务具体值配置-->
  12. <mirrors>
  13.     <mirror>
  14.             <id>aliyunmaven</id>
  15.             <mirrorOf>*</mirrorOf>
  16.             <name>阿里云公共仓库</name>
  17.             <url>https://maven.aliyun.com/repository/public</url>
  18.     </mirror>
  19. </mirrors>
  20. <!--配置maven插件-->
  21. <profiles>
  22.     <profile>
  23.       <id>jdk-11</id>
  24.       <activation>
  25.         <jdk>11.0.24</jdk>
  26.       </activation>
  27.       <repositories>
  28.         <repository>
  29.                       <id>central</id>
  30.                       <url>https://maven.aliyun.com/repository/central</url>
  31.                       <releases>
  32.                               <enabled>true</enabled>
  33.                       </releases>
  34.                       <snapshots>
  35.                               <enabled>true</enabled>
  36.                       </snapshots>
  37.         </repository>
  38.       </repositories>
  39.     </profile>
  40. </profiles>
  41. <!--配置其它-->
  42. <pluginGroups>
  43.         <pluginGroup>com.alibaba.org.apache.maven.plugins</pluginGroup>
  44.         <pluginGroup>com.alibaba.maven.plugins</pluginGroup>
  45. </pluginGroups>
  46. <activeProfiles>
  47.         <activeProfile>nexus</activeProfile>
  48. </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企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

熊熊出没

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表