1. 程式人生 > >Mac開發環境部署

Mac開發環境部署

1. 安裝 Xcode command line tools

xcode-select --install

2. 安裝 Homebrew

安裝 Homebrew 之前,必須先安裝 Xcode Command Line Tools。

在 terminal 中執行下面的命令,進行 homebrew 的安裝:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

下來,我們需要做一件事讓通過 Homebrew 安裝的程式的啟動連結(/usr/local/bin)可以直接執行,無需將完整路徑寫出。通過以下命令將 /usr/local/bin

新增到$PATH 環境變數中:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Cmd+T 開啟一個新的 terminal 標籤頁,執行以下命令,確保 brew 執行正常。

brew doctor

安裝完成後,Homwbrew 會將本地 /usr/local 初始化為 git 的工作樹,並將目錄所有者變更為當前所操作的使用者,將來 brew 的相關操作不需要 sudo 。

2.1 配置brew源

因為brew源的問題,可以修改為國內coding源。

cd "$(brew --repo)" && git remote set-url origin https://git.coding.net/homebrew/homebrew.git

cd $home && brew update

2.2 brew 使用命令

安裝一個包,可以簡單的執行:

brew install <package_name>

更新 Homebrew 在伺服器端上的包目錄:

brew update

檢視你的包是否需要更新:

brew outdated

更新包:

brew upgrade <package_name>

Homebrew 將會把老版本的包快取下來,以便當你想回滾至舊版本時使用。但這是比較少使用的情況,當你想清理舊版本的包快取時,可以執行:

brew cleanup

檢視你安裝過的包列表(包括版本號):

brew list --versions

3. 使用 Homebrew Cask安裝軟體

為什麼使用 Homebrew 安裝軟體?

  1. 步驟簡潔,直接一行命令就可以了。
  2. 方便管理,可以批量進行升級,免去一個個去檢查更新。

3.1 檔案預覽外掛

有些 外掛 可以讓 Mac 上的檔案預覽更有效,比如語法高亮、markdown 渲染、json 預覽等等。

brew cask install qlcolorcode qlstephen qlmarkdown quicklook-json qlprettypatch quicklook-csv  webpquicklook #suspicious-package

3.2 常用軟體

# 開發軟體
brew cask install shadowsocksx-ng 
brew cask install iterm2
brew cask install phpstorm  
brew cask install visual-studio-code    
brew cask install sublime-text  
brew cask install atom  
brew cask install sourcetree    
brew cask install filezilla 
brew cask install sequel-pro 
brew cask install dash  
brew cask install typora 

# 下載第三方應用
brew cask install sogouinput    
brew cask install qq 
brew cask install iina  
brew cask install dingtalk  
brew cask install alfred    
brew cask install appcleaner    
brew cask install cheatsheet    
brew cask install onedrive  
brew cask install google-chrome     
brew cask install youdaodict    
brew cask install youdaonote    
brew cask install microsoft-office  
brew cask install snipaste  
brew cask install aliwangwang   
brew cask install mos   
brew cask install jietu 
brew cask install neteasemusic  
brew cask install youku 
brew cask install qqmacmgr  
brew cask install qqlive

# 下載 MAS https://github.com/mas-cli/mas
brew install mas

# 下載 Mac App Store 應用

# 我的賬戶下的應用
mas install 836500024 789066512 409201541  409203825 409183694  724472954 425424353 1153157709  424182884 451108668

mas install 451108668 # qq
mas install 836500024 # wechat
mas install 789066512 # Maipo
mas install 409201541 # Pages 
mas install 409203825 # Numbers
mas install 409183694 # Keynote
mas install 724472954 # Manico
mas install 425424353 # The Unarchiver
mas install 1153157709 # Speedtest 測網速
mas install 424182884 # CHM Reader

# 切換奶牛登入 MAS 後再在 iterm 中執行下面的
# 奶牛賬戶下
mas install 443987910 972572731 904280696 948079084  453164367 458887729  852320343 1064959555  411643860 1063631769 823528286  955297617 441258766 967805235 1055273043

mas install 443987910 # 1Password
mas install 972572731 # Money Pro
mas install 904280696 # Things
mas install 948079084 # FlashFTP
mas install 453164367 # SystemPal
mas install 458887729 # Translate Tab
mas install 852320343 # Sketch
mas install 954188948 # MWeb
mas install 445189367 # PopClip
# mas install 915542151 # Monity
mas install 1064959555 # NewFileMenu
mas install 411643860 # DaisyDisk 磁碟檢視佔用
# mas install 975937182 # Fantastical 2 
# mas install   449830122 # HyperDock
# mas install 584653203 # Paw
# mas install 442160773 # Cocoa JSON Editor
mas install 1063631769 # Medis
# mas install 1031280567 # Postico
mas install 823528286 # Folx GO+ 
mas install 955297617 # CodeRunner3 
mas install 441258766 # magnet  視窗管理
mas install 967805235 # Paste
mas install 1055273043 # PDF Expert


# 切換到 Mindnote 賬戶
mas install 1289197285 

3.3 開發環境

# php
brew install php
# mysql
brew install [email protected]
# nginx
brew install nginx
# dnsmasq
brew install dnsmasq
# composer
brew install composer
# 也可以使用下面的原始安裝composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# redis
brew install redis

# 安裝 laravel
composer global require "laravel/installer"

# 安裝 valet
composer global require laravel/valet   #確保 ~/.composer/vendor/bin 目錄位於系統的「PATH」中

# 如果報錯執行下面的命令
export PATH="$PATH:$HOME/.composer/vendor/bin"
valet install # 執行 valet install 命令來配置和安裝 Valet 和 DnsMasq,並註冊 Valet 後臺隨機啟動。

# 建立工作區
mkdir ~/Codes
cd ~/Codes
valet park

# 如果遇到  Unable to determine linked PHP. 錯誤,執行下面的
brew link --force [email protected]


# 其他開發包安裝
brew install [email protected]

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc    #加入環境變數
/usr/local/Cellar/[email protected]/2.4.6/libexec/bin/plugin install mobz/elasticsearch-head   #安裝 head 外掛
/usr/local/Cellar/[email protected]/2.4.6/libexec/bin/plugin install analysis-kuromoji     #安裝日語分詞
brew services start [email protected]    #啟動 elasticsearch2.4

此外你還可以通過 brew cask 安裝 launchrocket,來管理通過 brew 安裝的 service

brew cask install launchrocket

4. iterm2 配置

ZSH安裝可以看這裡

# 檢查 zsh 版本
zsh --version
# 檢查終端預設 shell 期待 /bin/zsh
echo $SHELL

可以在安裝homebrew之前,檢查一下zsh的版本,如果版本比較新就不用管,如果比較舊則可以用brew install zsh 安裝一下。

brew install zsh-completions

安裝 oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

如果要使用什麼外掛,需要在 ~/.zshrc 檔案中進行新增。

subl ~/.zshrc

安裝字型

git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh
cd ..
rm -rf fonts

.zshrc 修改程式碼。

ZSH_THEME="agnoster"

隱藏前面的主機名,在 .zshrc 下面新增下面的程式碼。

prompt_context () { }

隱藏前面的使用者名稱在 .zshrc 下面新增下面的程式碼。

DEFAULT_USER="username"

隱藏第一行

touch ~/.hushlogin
#移除
rm ~/.hushlogin

外掛安裝

# zsh-autosuggestions 自動補全
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# zsh-syntax-highlighting 語法高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

plugins=(zsh-autosuggestions zsh-syntax-highlighting)

source ~/.zshrc

5. 終端ss配置

配置 subl命令,使用 sublime 開啟檔案,也可以使用 ~/.zshrc

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

subl ~/.bash_profile

vi ~/.bash_profile

~/.bash_profile 檔案下新增下面的程式碼:

export http_proxy=http://127.0.0.1:1087;
export https_proxy=http://127.0.0.1:1087;

下面是定義的開關方法。在終端直接輸入方法名就可以生效。

function ss_off(){
    unset http_proxy  # 如果不想設定方法,則單獨執行這兩句就可以刪除配置的環境變數
    unset https_proxy
    echo -e "已關閉代理"
}

function ss_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:1087" # 這裡也是埠號
    export https_proxy=$http_proxy
    echo -e "已開啟代理"
}

重新整理環境

source ~/.bash_profile

開啟

ss_off

檢查是否生效

curl ip.cn

關閉 brew 更新

.zshrc 中新增

export HOMEBREW_NO_AUTO_UPDATE=true

6. Git ssh的配置和使用

6.1 設定 Git 的 user name 和 email:(如果是第一次的話)

git config --global user.name "****"
git config --global user.email "***@**.com"

檢視配置資訊

# 檢視本地全域性使用者配置資訊
git config --global  --list

6.2 生成金鑰

ssh-keygen -t rsa -C "***@**.com"       

6.3 拷貝金鑰到 github

cat ~/.ssh/id_rsa.pub

6.4 測試

ssh -T [email protected]

7. 常用軟體配置

7.1 SS

在偏好配置的網路介面中 忽略這些主機和域的代理設定 中新增:

127.0.0.1, localhost, 192.168.0.0/16, 10.0.0.0/8, FE80::/64, ::1, FD00::/8,shop.test,box.test,ccshop.test,account.jetbrains.com

這裡把本地需要訪問的域名全部加進去,這樣開啟全域性的時候就不會走ss。

7.2 PhpStorm

在Github建立一個用於phpstorm配置的倉庫,然後通過下面的方法備份和同步。

File->Settings Repository 中輸入git倉庫地址,然後點選覆蓋遠端和本地來選擇同步方式。

同步完設定後,安裝常用的擴充套件包:

  • Laravel Plugin
  • Material Theme UI
  • Translation
  • Dash