本文主要内容:
- 1.Mac OS 10.11.6 [OS X EL Captain]
- 2.Mac OS 安装Java 设置环境变量
- 3.Mac OS 安装Maven设置环境变量
- 4.Mac OS 安装Tomcat设置环境变量
- 5.Mac OS 安装HomeBrew服务器
- 6.Mac OS 安装Git 服务器
Mac OS是一套运行于苹果Macintosh系列电脑上的操作系统。Mac OS是首个在商用领域成功的图形用户界面操作系统。Mac系统是基于Unix内核的图形化操作系统;一般情况下在普通PC上无法安装的操作系统。由苹果公司自行开发。新系统非常可靠;它的许多特点和服务都体现了苹果公司的理念。现行的最新的系统版本是macOS Sierra 10.12,且网上也有在PC上运行的Mac系统,简称 Mac PC。—— [ 百度百科 ]
2011年7月20日Mac OS X已经正式被苹果改名为OS X。最新版本为10.10,2014年10月21日凌晨1点发布。
2016年6月13日,在苹果开发者大会WWDC发布了产品Mac OS的新功能。
由于我的电脑上预装的OS X El Capitan 10.11.6,OS X El Capitan系统是苹果2015年9月29日宣布的作为免费更新面向Mac用户提供的操作系统。
因此,我的实践均和OS X El Capitan 10.11.6 版本有关,其他版本出现问题或安装失败,请自行参照其他博主的教程。
1.获取Java 安装包: [ Java 安装包获取地址]。
在下载Java 安装包的时候一定要下载 Java JDK ,别下载 Java JRE,因为Java JDK 里面包含有Java JRE ,而Java JRE 并不不包含 Java JDK 。 我下载的是 Java JDK 1.8,Mac OS 版本 。
2.正常安装Java JDK 1.8 ,一直默认安装就好,直到完成。
3.接下来是本教程的核心内容,就是设置环境变量:
3.1 打开终端,输入echo Shell,查看系统使用shell脚本类型,如果输出的是bash,说明是Bourneshell,是默认的UnixShell命令。注意,echo Shell 的S一定是大写,否则会报错。
3.2 输入java-version查看java 版本信息,如果安装成功就会输出如下信息:
Last login: Tue Jan 17 21:52:09 on ttys002
Marklins-Mac: ~ marklin$ java -version
java version “1.8.0_112”
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)
Marklins-Mac:~ marklin$
如果不是的话,说明没有安装成功,需要检查原因,重新安装后再执行此操作。
3.3 使用工具命令“/usr/libexec/java_home”来定位JAVA_HOME:
MarkAppledeMac:~ markapple$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
1.8.0_111,
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
如果出现 /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home,这就是Java 的安装路径,就是Windows 系统所说的Path。
3.4 配置JAVA_HOME:输入sudo vim etc/profile,进入vim编辑器view视图
3.5 键盘输入i,进入插入模式,在文件尾部添加java安装路径:
JAVA_HOME=”/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home”
CLASS_PATH=”$JAVA_HOME/lib”
PATH=”.; PATH: JAVA_HOME/bin”
export JAVA_HOME
3.6 添加完毕之后,按esc退出插入模式,并键入wq!保存退出文件
3.7 如果保存时出现:vi E212:Can’t open file for writing 说明你没有修改权限,如果没有说明已经构建成功,不用执行8-10操作
3.8 退出vim编辑器,在终端输入 sudo su命令,输入开机密码
3.9 输入vi /etc/profile 命令,进入vim编辑器view视图
3.10 键盘输入i,进入插入模式,在文件尾部添加java安装路径:
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home"
CLASS_PATH="$JAVA_HOME/lib"
PATH=".;$PATH:$JAVA_HOME/bin"
export JAVA_HOME
3.11 输入echo $JAVA_HOME查看路径是否正确,如果正确则继续下面的操作,如果不正确则需要修改
3.12 输入source ~/.profile 使得修改的文件生效
3.13 输入java 命令,到此设置完毕
MarkAppledeMac:~ markapple$ java
用法: java [-options] class [args…]
(执行类)
或 java [-options] -jar jarfile [args…]
(执行 jar 文件)
其中选项包括:
-d32 使用 32 位数据模型 (如果可用)
-d64 使用 64 位数据模型 (如果可用)
-server 选择 “server” VM
默认 VM 是 server,
因为您是在服务器类计算机上运行。
-cp <目录和 zip/jar 文件的类搜索路径>
-classpath <目录和 zip/jar 文件的类搜索路径>
用 : 分隔的目录, JAR 档案
和 ZIP 档案列表, 用于搜索类文件。
-D<名称>=<值>
设置系统属性
-verbose:[class|gc|jni]
启用详细输出
-version 输出产品版本并退出
-version:<值>
警告: 此功能已过时, 将在
未来发行版中删除。
需要指定的版本才能运行
-showversion 输出产品版本并继续
-jre-restrict-search | -no-jre-restrict-search
警告: 此功能已过时, 将在
未来发行版中删除。
在版本搜索中包括/排除用户专用 JRE
-? -help 输出此帮助消息
-X 输出非标准选项的帮助
-ea[:...|:]
-enableassertions[:...|:]
按指定的粒度启用断言
-da[:...|:]
-disableassertions[:...|:]
禁用具有指定粒度的断言
-esa | -enablesystemassertions
启用系统断言
-dsa | -disablesystemassertions
禁用系统断言
-agentlib:[=<选项>]
加载本机代理库 , 例如 -agentlib:hprof
另请参阅 -agentlib:jdwp=help 和 -agentlib:hprof=help
-agentpath:[=<选项>]
按完整路径名加载本机代理库
-javaagent:[=<选项>]
加载 Java 编程语言代理, 请参阅 java.lang.instrument
-splash:
使用指定的图像显示启动屏幕
有关详细信息, 请参阅 http://www.oracle.com/technetwork/java/javase/documentation/index.html。
还可以:打开终端,输入touch .bash_profile,输入open .bash_profile打开记事本:
JAVA_HOME=”/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home”
CLASS_PATH=”$JAVA_HOME/lib”
PATH=”.; PATH: JAVA_HOME/bin”
export JAVA_HOME
更新配置的环境变量source .bash_profile,使得环境变量生效,可以输入 Java 进行验证。
1.获取Maven 安装包: [ Maven 安装包获取地址]。
注意,下载Maven 的时候一定是下载:apache-maven-3.3.9-src.tar.gz,然后在桌面新建一个文件夹,名称自定义,但是一定要为英文,不可为中文。我的文件名:ApplicationsTools
2.打开终端,输入touch .bash_profile,再次输入open .bash_profile打开记事本:
JAVA_HOME=”/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home”
CLASS_PATH=” JAVAHOME/lib”M2HOME=”/Users/markapple/Desktop/ApplicationsTools/apache−maven−3.3.9”PATH=”.; PATH: JAVAHOME/bin: M2_HOME/bin”
export JAVA_HOME
export M2_HOME
export PATH=”/usr/local/bin:/usr/local/sbin:~/bin:$PATH”
2.在终端输入source ~/.bash_profile,再输入:mvn -v。
MarkAppledeMac:~ markapple$ touch .bash_profile
MarkAppledeMac:~ markapple$ open .bash_profile
MarkAppledeMac:~ markapple$ source ~/.bash_profile
MarkAppledeMac:~ markapple$ mvn -v
2015-11-11T00:41:47+08:00)
Maven home: /Users/markapple/Desktop/ApplicationsTools/apache-maven-3.3.9
Java version: 1.8.0_111, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: “mac os x”, version: “10.11.6”, arch: “x86_64”, family: “mac”
1.获取Tomcat安装包: [Tomcat安装包获取地址]。
注意,下载Maven 的时候一定是下载:Tomcat.tar.gz,然后在桌面新建一个文件夹,名称自定义,但是一定要为英文,不可为中文。我的文件名:ApplicationsTools,就是之前放Maven的文件夹,放在一起方便查找和管理。
2.打开终端,输入touch .bash_profile,再次输入open .bash_profile打开记事本:
PATH=”.; PATH: JAVA_HOME/bin: M2HOME/bin:/Users/markapple/Desktop/dev/applications/Tomcat9/bin”3.更新配置的环境变量source.bashprofile验证是否成功,终端中输入 PATH
显示如下-bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/keso/Library/Tomcat8/bin: No such file or directory
5.终端中输入startup.sh, startup.sh后出现类似 “Permission denied” ,这个时候需要对目录进行权限设置:输入 sudo chmod 755 Library/Tomcat8/bin/*.sh 回车,设置文件的读写执行权限;
MarkAppledeMac:~
markapple sudochmod755/Users/markapple/Desktop/dev/applications/Tomcat9/bin/∗.shPassword:MarkAppledeMac: markapple startup.sh
Using CATALINA_BASE: /Users/markapple/Desktop/dev/applications/Tomcat9
Using CATALINA_HOME: /Users/markapple/Desktop/dev/applications/Tomcat9
Using CATALINA_TMPDIR: /Users/markapple/Desktop/dev/applications/Tomcat9/temp
Using JRE_HOME:
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
Using CLASSPATH:
/Users/markapple/Desktop/dev/applications/Tomcat9/bin/bootstrap.jar:/Users/markapple/Desktop/dev/applications/Tomcat9/bin/tomcat-juli.jar
Tomcat started.
7.关闭需要使用shutdown.sh即可;
1.HomeBrew :.获取Tomcat安装包: [HomeBrew 管理器官网 ]。
macOS 不可或缺的套件管理器
2.打开终端,输入:ruby -e “$(curl –insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” 后回车:
Last login: Tue Jan 17 20:00:48 on console
Marklins-Mac:~ marklin ruby−e" (curl –insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var
Press RETURN to continue or any other key to abort :
3.继续回车:
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
Password:
4 .输入开机密码,继续回车,你是看不见的密码的:
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown marklin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/mkdir -p /Users/marklin/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/marklin/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown marklin /Users/marklin/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown marklin /Library/Caches/Homebrew
==> Downloading and installing Homebrew…
remote: Counting objects: 4487, done.
remote: Compressing objects: 100% (2914/2914), done.
remote: Total 4487 (delta 2381), reused 2898 (delta 1417), pack-reused 0
Receiving objects: 100% (4487/4487), 2.52 MiB | 565.00 KiB/s, done.
Resolving deltas: 100% (2381/2381), done.
From https://github.com/Homebrew/brew
* [new branch] master -> origin/master
* [new tag] 0.1 -> 0.1
* [new tag] 0.2 -> 0.2
* [new tag] 0.3 -> 0.3
* [new tag] 0.4 -> 0.4
* [new tag] 0.5 -> 0.5
* [new tag] 0.6 -> 0.6
* [new tag] 0.7 -> 0.7
* [new tag] 0.7.1 -> 0.7.1
* [new tag] 0.8 -> 0.8
* [new tag] 0.8.1 -> 0.8.1
* [new tag] 0.9 -> 0.9
* [new tag] 0.9.1 -> 0.9.1
* [new tag] 0.9.2 -> 0.9.2
* [new tag] 0.9.3 -> 0.9.3
* [new tag] 0.9.4 -> 0.9.4
* [new tag] 0.9.5 -> 0.9.5
* [new tag] 0.9.8 -> 0.9.8
* [new tag] 0.9.9 -> 0.9.9
* [new tag] 1.0.0 -> 1.0.0
* [new tag] 1.0.1 -> 1.0.1
* [new tag] 1.0.2 -> 1.0.2
* [new tag] 1.0.3 -> 1.0.3
* [new tag] 1.0.4 -> 1.0.4
* [new tag] 1.0.5 -> 1.0.5
* [new tag] 1.0.6 -> 1.0.6
* [new tag] 1.0.7 -> 1.0.7
* [new tag] 1.0.8 -> 1.0.8
* [new tag] 1.0.9 -> 1.0.9
* [new tag] 1.1.0 -> 1.1.0
* [new tag] 1.1.1 -> 1.1.1
* [new tag] 1.1.2 -> 1.1.2
* [new tag] 1.1.3 -> 1.1.3
* [new tag] 1.1.4 -> 1.1.4
* [new tag] 1.1.5 -> 1.1.5
* [new tag] 1.1.6 -> 1.1.6
* [new tag] 1.1.7 -> 1.1.7
HEAD is now at eece770 Merge pull request #1815 from MikeMcQuaid/dependency_to_formula
5 .继续回车 :
==> Tapping homebrew/core
Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…
remote: Counting objects: 3834, done.
remote: Compressing objects: 100% (3711/3711), done.
remote: Total 3834 (delta 25), reused 348 (delta 8), pack-reused 0
Receiving objects: 100% (3834/3834), 3.06 MiB | 461.00 KiB/s, done.
Resolving deltas: 100% (25/25), done.
Checking out files: 100% (3839/3839), done.
Tapped 3707 formulae (3,863 files, 9.6M)
==> Cleaning up /Library/Caches/Homebrew…
==> Migrating /Library/Caches/Homebrew to /Users/marklin/Library/Caches/Homebrew
==> Deleting /Library/Caches/Homebrew…
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
https://git.io/brew-analytics
==> Next steps:
- Run brew help
to get started
- Further documentation:
https://git.io/brew-docs
Marklins-Mac:~ marklin Marklins−Mac: marklin ruby -e "$(curl –insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown marklin /Library/Caches/Homebrew
==> Downloading and installing Homebrew…
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at eece770 Merge pull request #1815 from MikeMcQuaid/dependency_to_formula
==> Cleaning up /Library/Caches/Homebrew…
==> Migrating /Library/Caches/Homebrew to /Users/marklin/Library/Caches/Homebrew
==> Deleting /Library/Caches/Homebrew…
Already up-to-date.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
https://git.io/brew-analytics
==> Next steps:
- Run brew help
to get started
- Further documentation:
https://git.io/brew-docs
Marklins-Mac:~ marklin$
到这,HomeBrew 管理器就安装完成了!
打开终端,输入 brew install git 后一直回车就好不用顾忌,安装完成后,就可以brew install gcc 都完成后 输入 git -version 和 which git 验证是否成功,失败重新来过!