對於每一名開發者來講,更換系統或者更換電腦的時候,都免不了花上不短的時間去折騰開 發環境的問題。我本人也是三番兩次,深知這個過程的繁瑣。全部,根據我本身以往的經驗, 以及參考一下他人的意見,整理一下關於在Mac下作各類開發的配置,包含Java, Ruby, Vim, git, 數據庫等等。歡迎補充與修正。javascript
這篇文章包含配置控制檯環境,包括包管理工具, zsh, Vim, git的安裝配置。css
包管理工具已經成爲如今操做系統中不可缺乏的一個重要工具了,它能大大減輕軟件安裝的 負擔,節約咱們的時間。Linux中經常使用的有yum
和apt-get
工具,甚至Windows平臺也 有Chocolatey
這樣優秀的工具,OSX平臺天然有它獨有的工具。html
在OSX中,有兩款你們經常使用的管理工具:Homebrew
或者MacPorts
。這兩款工具都是爲了解決同 樣的問題——爲OSX安裝經常使用庫和工具。Homebrew與MacPorts的主要區別是Homebrew不會破壞OSX 原生的環境,這也是我推薦Homebrew的主要緣由。同時它安裝的全部文件都是在用戶獨立空間內 的,這讓你安裝的全部軟件對於該用戶來講都是能夠訪問的,不須要使用sudo
命令。html5
在安裝Homebrew前,你須要前往AppStore下載並安裝Xcode.java
安裝方式:jquery
1
2 3 |
# OSX系統基本上都自帶Ruby1.9 # 因此無需先安裝Ruby,可是以後咱們須要管理Ruby ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
Homebrew
經常使用命令:nginx
1
2 3 4 5 6 7 8 9 10 |
brew list # 查看已經安裝的包 brew update # 更新Homebrew自身 brew doctor # 診斷關於Homebrew的問題(Homebrew 有問題時請用它) brew cleanup # 清理老版本軟件包或者無用的文件 brew show ${formula} # 查看包信息 brew search ${formula} # 按名稱搜索 brew upgrade ${formula} # 升級軟件包 brew install ${formula} # 按名稱安裝 brew uninstall ${formula} # 按名稱卸載 brew pin/unpin ${formula} # 鎖定或者解鎖軟件包版本,防止誤升級 |
Shell程序就是Linux/UNIX系統中的一層外殼,幾乎全部的應用程序均可以運行在Shell環境 下,經常使用的有bash, csh, zcsh等。在/etc/shells
文件中能夠查看系統中的各類shell。git
1
2 3 4 5 6 7 8 9 10 11 12 |
cat /etc/shells # List of acceptable shells for chpass(1). # Ftpd will not allow users to connect who are not using # one of these shells. /bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh |
而zsh是OSX系統原生的shell之一,其功能強大,語法相對於bash更加友好和強大,因此推薦 使用zsh做爲默認的shell。github
1
2 |
# 切換zsh爲默認shell chsh -s $(which zsh) |
若是你想使用最新的zsh,你可使用Homebrew,此方法也會保留原生的zsh,防止你在某個 時刻須要它。sql
1
2 3 4 5 6 7 8 9 10 11 12 |
# 查看最新zsh信息 brew info zsh # 安裝zsh brew install --disable-etcdir zsh # 添加shell路徑至/etc/shells文件中 # 將 /usr/local/bin/zsh 添加到下面文件中 sudo vim /etc/shells # 更換默認shell chsh -s /usr/local/bin/zsh |
下面貼上個人zsh配置以供參考
個人zsh配置 (zshrc)download
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# modify the prompt to contain git branch name if applicable git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) if [[ -n $ref ]]; then echo " %{$fg_bold[green]%}${ref#refs/heads/}%{$reset_color%}" fi } setopt promptsubst export PS1='${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[blue]%}%c%{$reset_color%}$(git_prompt_info) %# ' # load our own completion functions fpath=(~/.zsh/completion $fpath) # completion autoload -U compinit compinit # load custom executable functions for function in ~/.zsh/functions/*; do source $function done # makes color constants available autoload -U colors colors # enable colored output from ls, etc export CLICOLOR=1 # history settings setopt hist_ignore_all_dups inc_append_history HISTFILE=~/.zhistory HISTSIZE=4096 SAVEHIST=4096 # awesome cd movements from zshkit setopt autocd autopushd pushdminus pushdsilent pushdtohome cdablevars DIRSTACKSIZE=5 # Enable extended globbing setopt extendedglob # Allow [ or ] whereever you want unsetopt nomatch # vi mode bindkey -v bindkey "^F" vi-cmd-mode bindkey jj vi-cmd-mode # handy keybindings bindkey "^A" beginning-of-line bindkey "^E" end-of-line bindkey "^R" history-incremental-search-backward bindkey "^P" history-search-backward bindkey "^Y" accept-and-hold bindkey "^N" insert-last-word bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy" # use vim as the visual editor export VISUAL=vim export EDITOR=$VISUAL # load rbenv if available if which rbenv &>/dev/null ; then eval "$(rbenv init - --no-rehash)" fi # load thoughtbot/dotfiles scripts export PATH="$HOME/.bin:$PATH" # mkdir .git/safe in the root of repositories you trust export PATH=".git/safe/../../bin:$PATH" # aliases [[ -f ~/.aliases ]] && source ~/.aliases # Local config [[ -f ~/.zshrc.local ]] && source ~/.zshrc.local |
對於Vim,無需溢美之詞,做爲與emacs並列的兩大編輯器,早已經被無數人奉爲經典。而它卻 又以超長的學習曲線,使得不少人望而卻步。長久以來,雖然擁有大量的插件,卻缺乏一個 確之有效的插件管理器。所幸,Vundle
的出現解決了這個問題。
Vundle
可讓你在配置文件中管理插件,而且很是方便的查找、安裝、更新或者刪除插件。 還能夠幫你自動配置插件的執行路徑和生成幫助文件。相對於另一個管理工具pathogen
, 能夠說有着巨大的優點。
1
2 |
# vundle 安裝和配置 git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
" 將下面配置文件加入到.vimrc文件中 set nocompatible " 必須 filetype off " 必須 " 將Vundle加入運行時路徑中(Runtime path) set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() " 使用Vundle管理插件,必須 Plugin 'gmarik/Vundle.vim' " " 其餘插件 " call vundle#end() " 必須 filetype plugin indent on " 必須 |
最後,你只須要執行安裝命令,便可以安裝好所需的插件。
1
2 3 4 5 |
# 在vim中 :PluginInstall # 在終端 vim +PluginInstall +qall |
下面列出個人Vim插件和配置
Vim插件 (vimrc.bundles)download
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
if &compatible set nocompatible end filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " Let Vundle manage Vundle Bundle 'gmarik/vundle' " Define bundles via Github repos Bundle 'christoomey/vim-run-interactive' Bundle 'croaky/vim-colors-github' Bundle 'danro/rename.vim' Bundle 'kchmck/vim-coffee-script' Bundle 'kien/ctrlp.vim' Bundle 'pbrisbin/vim-mkdir' Bundle 'scrooloose/syntastic' Bundle 'slim-template/vim-slim' Bundle 'thoughtbot/vim-rspec' Bundle 'tpope/vim-bundler' Bundle 'tpope/vim-endwise' Bundle 'tpope/vim-fugitive' Bundle 'tpope/vim-rails' Bundle 'tpope/vim-surround' Bundle 'vim-ruby/vim-ruby' Bundle 'vim-scripts/ctags.vim' Bundle 'vim-scripts/matchit.zip' Bundle 'vim-scripts/tComment' Bundle "mattn/emmet-vim" Bundle "scrooloose/nerdtree" Bundle "Lokaltog/vim-powerline" Bundle "godlygeek/tabular" Bundle "msanders/snipmate.vim" Bundle "jelera/vim-javascript-syntax" Bundle "altercation/vim-colors-solarized" Bundle "othree/html5.vim" Bundle "xsbeats/vim-blade" Bundle "Raimondi/delimitMate" Bundle "groenewege/vim-less" Bundle "evanmiller/nginx-vim-syntax" Bundle "Lokaltog/vim-easymotion" Bundle "tomasr/molokai" if filereadable(expand("~/.vimrc.bundles.local")) source ~/.vimrc.bundles.local endif filetype on |
Vim配置 (vimrc)download
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
" Use Vim settings, rather then Vi settings. This setting must be as early as " possible, as it has side effects. set nocompatible " Highlight current line au WinLeave * set nocursorline nocursorcolumn au WinEnter * set cursorline cursorcolumn set cursorline cursorcolumn " Leader let mapleader = "," set backspace=2 " Backspace deletes like most programs in insert mode set nobackup set nowritebackup set noswapfile " http://robots.thoughtbot.com/post/18739402579/global-gitignore#comment-458413287 set history=50 set ruler " show the cursor position all the time set showcmd " display incomplete commands set incsearch " do incremental searching set laststatus=2 " Always display the status line set autowrite " Automatically :write before running commands set confirm " Need confrimation while exit set fileencodings=utf-8,gb18030,gbk,big5 " Switch syntax highlighting on, when the terminal has colors " Also switch on highlighting the last used search pattern. if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on") syntax on endif if filereadable(expand("~/.vimrc.bundles")) source ~/.vimrc.bundles endif filetype plugin indent on augroup vimrcEx autocmd! " When editing a file, always jump to the last known cursor position. " Don't do it for commit messages, when the position is invalid, or when " inside an event handler (happens when dropping a file on gvim). autocmd BufReadPost * \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif " Cucumber navigation commands autocmd User Rails Rnavcommand step features/step_definitions -glob=**/* -suffix=_steps.rb autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb -default=routes " Set syntax highlighting for specific file types autocmd BufRead,BufNewFile Appraisals set filetype=ruby autocmd BufRead,BufNewFile *.md set filetype=markdown " Enable spellchecking for Markdown autocmd FileType markdown setlocal spell " Automatically wrap at 80 characters for Markdown autocmd BufRead,BufNewFile *.md setlocal textwidth=80 augroup END " Softtabs, 2 spaces set tabstop=2 set shiftwidth=2 set shiftround set expandtab |