1 下載Gradle
先檢查java環境,是否安裝了jdk或者jre 8或者以上版本:
java -version java version "1.8.0_121"
官網下載:https://gradle.org/releases
選擇某一版本的binary-only進行下載,例如:
將下載的文件解壓到某一目錄下,例如:
sudo unzip -d /usr/local gradle-5.4.1-bin.zip
2 配置環境變量
編輯bash_profile文件:
vi ~/.bash_profile
加入如下內容:
#GRADLE GRADLE_HOME=/usr/local/gradle-5.4.1 PATH=$PATH:$GRADLE_HOME/bin export GRADLE_HOME GRADLE_USER_HOME PATH
執行下面命令使內容生效:
source ~/.bash_profile
測試安裝是否成功:
gradle -v
出現下面內容表示安裝成功:
ycyzharrydeMacBook-Pro:~ ycyzharry$ gradle -v Welcome to Gradle 5.4.1! Here are the highlights of this release: - Run builds with JDK12 - New API for Incremental Tasks - Updates to native projects, including Swift 5 support For more details see https://docs.gradle.org/5.4.1/release-notes.html ------------------------------------------------------------ Gradle 5.4.1 ------------------------------------------------------------ Build time: 2019-06-26 08:14:42 UTC Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d Kotlin: 1.3.21 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_212 (Oracle Corporation 25.212-b10) OS: Mac OS X 10.14.2 x86_64