从零开始搭建MacOS开发环境

基础软件

生成SSH密钥

# 执行这个命令一路回车就好,生成的文件在 ~/.ssh/ 目录下
ssh-keygen -t rsa

# id_rsa 私钥
# id_rsa.pub 公钥文件 ssh免密登录 github ssh推送到分发这个文件

oh-my-zsh

zsh相比bash在界面层面更加出色,减少很多手动配置的过程

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

brew

brew是Mac下的软件包管理工具。可以方便我们安装、升级、卸载软件。也可以管理启动服务。

# 安装脚本 在国内被墙了
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# 安装软件
brew install ${软件名}
# 升级
brew upgrade ${软件名}
# 卸载
brew uninstall ${软件名}
# 详情
brew detail ${软件名}
# 搜索
brew search ${关键词}

git

# 安装
brew install git
git config --global user.name "名字"
git config --global user.email "邮箱"

vim 最好的终端编辑器,没有之一

# 安装
brew install vim

# 安装插件管理器
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

.vimrc文件

" 打开代码高亮
syntax enable

" 设置配色方案

" 显示行号
set number

" 高亮当前行
set cursorline

" 显示80列线
set cc=80

" 字符编码设置为utf8
set encoding=utf8

"代码折叠 indent:以缩进表示
set fdm=indent

" 状态栏设置为2行
set laststatus=2

" Tab设置为4个空格
set tabstop=4
set shiftwidth=4
set backspace=indent,eol,start
set expandtab

" 设置为256色
set t_Co=256

set nocompatible              " be iMproved, required
filetype off                  " required

" tagslist 设置
let Tlist_Auto_Open = 1
let Tlist_Use_Right_Window = 1  
let Tlist_File_Fold_Auto_Close=1
let Tlist_Exit_OnlyWindow=1
map tl :TlistToggle<cr> 

" WinManager 设置
let g:winManagerWindowLayout='FileExplorer|BufExplorer'
let g:persistentBehaviour=0
nmap wm :WMToggle<cr>

" Supertab设置
let g:SuperTabDefaultCompletionType="context"
let g:SuperTabRetainCompletionType=2
let g:SuperTabNoCompleteAfter = ['^', ',', '\s', '\t']

" Syntastic设置
let g:syntastic_check_on_open = 1

" Markdown配置
let g:vim_markdown_math=1
let g:vim_markdown_frontmatter=1

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""Syntastic设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:syntastic_check_on_open = 1
let g:syntastic_error_symbol = 'x'
let g:syntastic_warning_symbol = '!'
let g:syntastic_phpcs_conf = "--tab-width=4"
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd' ]
let g:syntastic_mode_map = { 'passive_filetypes' : ['phtml'] }


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""neocomplcache 设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:neocomplcache_enable_at_startup = 1
imap <C-k>     <Plug>(neosnippet_expand_or_jump)
smap <C-k>     <Plug>(neosnippet_expand_or_jump)
xmap <C-k>     <Plug>(neosnippet_expand_target)

" SuperTab like snippets behavior.
imap <expr><TAB> neosnippet#expandable_or_jumpable() ?   "\<Plug>(neosnippet_expand_or_jump)" : pumvisible() ? "\<C-n>" : "\<TAB>"
smap <expr><TAB> neosnippet#expandable_or_jumpable() ?   "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
"
" " For snippet_complete marker.
if has('conceal')
   set conceallevel=2 concealcursor=i
endif

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

Plugin 'ervandew/supertab' "TAB键加强
Plugin 'vim-scripts/taglist.vim' "TagList
Plugin 'scrooloose/syntastic' "代码检查
Plugin 'Lokaltog/vim-powerline' " 状态行插件
Plugin 'Shougo/neocomplcache.vim' " 代码补全插件
Plugin 'Shougo/neosnippet' " 代码提示插件
Plugin 'Shougo/neosnippet-snippets' " 代码片段
Plugin 'uarun/vim-protobuf' "Google Protobuf支持
Plugin 'othree/xml.vim' "XML语法支持
Plugin 'plasticboy/vim-markdown' "Markdown支持

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
autocmd BufRead,BufNewFile *.phtml set filetype=html.php
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

nginx

#  安装命令
brew install nginx

# 默认doc目录
/usr/local/var/www

# 默认端口
8080

# 配置文件目录
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/servers/

# 命令
brew services start nginx
brew services stop nginx

mysql

# 安装
brew install mysql@5.7

# 路径处理
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
export PKG_CONFIG_PATH="/usr/local/opt/mysql@5.7/lib/pkgconfig"

# 在后台运行mysql
brew services start mysql@5.7

# 在前台运行mysql
/usr/local/opt/mysql@5.7/bin/mysql.server start

redis

# 安装
brew install redis
# 后台启动
brew services start redis
# 前台启动
redis-server /usr/local/etc/redis.conf

常用shell命令

tree 查看目录结构

brew install tree

wget http客户端

brew install wget

Java环境

jdk

# 安装openjdk8
brew install homebrew/cask-versions/adoptopenjdk8

idea 插件

  1. Alibaba Java Coding Guidelines
  2. Spring Assistant
  3. IdeaVim
  4. Free Mybatis plugin
  5. Lombok
  6. .ignore
  7. PlantUML integration
  8. MapStruct support
  9. Protobuf Support

maven

# 安装
brew install maven

~/.m2/settings.xml

<?xml version="1.0" encoding="UTF-8" ?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<mirrors>
    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
</mirrors>
<profiles>
    <profile>
        <id>jdk18</id>
        <activation>
            <jdk>1.8</jdk>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>
</profiles>

</settings>

Python环境

python3

# 安装python最新版
brew install python
# 虚拟环境 
python3 -m venv <DIR>
source <DIR>/bin/activate
# pip
pip3 install ""

python2

# 安装python最新版
brew install python@2.7
# 虚拟环境 
virtualenv <DIR>
source <DIR>/bin/activate
# pip
pip install ""

PHP环境

# 安装
brew install php
# 配置文件地址
/usr/local/etc/php/7.3/
# 后台启动
brew services start php
# 控制台启动
php-fpm

js环境

# 安装node
brew install node
# 安装淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org

visual studio code 插件

  • vim

生产力

xmind

Typora

TextMate

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容