macOS 重裝系統開發環境

系統內置

編程語言:php

  • bash 3.2.57
  • ruby 2.3.7
  • perl 5.18.4
  • python 2.7.10
  • php 7.1.23

實用程序:node

  • curl 7.54.0
  • ssh 7.9

命令行開發者工具

使用以下命令:python

ls -l /usr/bin | grep -E "git|make|gcc"
複製代碼

能夠看到,系統有內置 git, make, gcc 等工具。可是,當你執行其中一個命令時,好比 git --version ,就會出現以下彈窗。提示須要安裝 Xcode 或來自 App Store 的命令行開發工具才能使用。二者仍選一個均可以。但若是不是作IOS開發,安裝 Xcode 又過於重了。所以,選擇輕量級的命令行就能夠了。c++

安裝了命令行開發這工具後,如下程序均可以在命令行順利地使用了。git

  • git 2.20.1
  • make 3.81
  • gcc

git 與 github

剛剛完成 git 安裝,一般咱們須要作一些初始化配置。如:開啓顏色顯示(用於 git log ,git status ,git diff等輸出信息的高亮),設置全局用戶名和郵箱。github

git config --global color.ui true
git config --global user.name "your name"
git config --global user.email "your email"
git config -l
複製代碼

若是想 push 代碼到 github 更加順滑一些,還須要配置 ssh 密鑰。首先生成密鑰對,並將公鑰複製到剪貼板。shell

ssh-keygen -t rsa -b 4096 -C "your github account email"
eval "$(ssh-agent -s)"
pbcopy < ~/.ssh/id_rsa.pub
複製代碼

github 粘貼SSH keys: github.com/settings/ke…npm

測試是否可用:編程

$ ssh -T git@github.com
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. 複製代碼

homebrew

homebrew (brew) 是 macOS 系統的命令行軟件安裝工具,使用 ruby 編寫。其做用至關於 CentOS 的 yum 或 Ubuntu 的 apt-get 。但不一樣的是,homebrew 並非內置的安裝工具,由於官方的軟件安裝工具固然是 App Store 。不少爲 macOS 編寫的命令行程序,都採用 brew 方式安裝。vim

安裝 homebrew 的方式以下:

$ /usr/bin/ruby -e "$(curl -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/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Homebrew
/usr/local/Frameworks
複製代碼

nodejs

下載LTS版:nodejs.org/dist/v12.13…

雙擊安裝:

sudo npm install -g n
sudo n 8.12
sudo n lts
sudo n latest
複製代碼

安裝 yarn :

curl -o- -L https://yarnpkg.com/install.sh | bash
複製代碼

都安裝到哪了?

$ ls -l /usr/local/bin/
total 82576
lrwxr-xr-x  1 ken       admin        28 10 23 20:22 brew -> /usr/local/Homebrew/bin/brew
lrwxr-xr-x  1 ken       admin        27 10 23 20:51 n -> ../lib/node_modules/n/bin/n
-rwxr-xr-x  1 root      wheel  42276320 10 21 15:53 node
lrwxr-xr-x  1 root      admin        38 10 23 20:45 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxr-xr-x  1 root      admin        38 10 23 20:45 npx -> ../lib/node_modules/npm/bin/npx-cli.js
複製代碼

anaconda

安裝配置 anaconda :

# 安裝
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.10-MacOSX-x86_64.sh
sh Anaconda3-2019.10-MacOSX-x86_64.sh
# 初始化
~/anaconda3/bin/conda init
. ~/.bash_profile
# 自動激活配置與清華鏡像
conda config --set auto_activate_base false
cat << END >> ~/.condarc
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
END
# 測試建立 python3.6 環境
conda create -n py36 python==3.6
conda activate py36
conda deactivate
複製代碼

添加 c++ kernel:

conda activate base
conda install xeus-cling -c conda-forge
jupyter kernelspec list
複製代碼

添加 nodejs kernel:

conda create -n nodejs
conda activate nodejs
conda install jupyter notebook
git clone https://github.com/3Nigma/nelu-kernelu.git
cd nelu-kernelu
# nodejs v12.3+
npm install
test -d ~/notebook || mkdir ~/notebook
cd ~/notebook
jupyter notebook
複製代碼

設置終端配色

cat << END >> ~/.bash_profile

# export LS_OPTIONS='--color=auto' # 若是沒有指定,則自動選擇顏色
export CLICOLOR='Yes'                        # 是否輸出顏色
export LSCOLORS='ExGxFxdaCxDaDahbadacec'     # 指定顏色
END
複製代碼

設置 vim 配色

test -f ~/.vimrc || cp /usr/share/vim/vimrc ~/.vimrc

cat << END >> ~/.vimrc

" 修改配色 begin colorscheme default " 設置顏色主題

syntax on               " 語法高亮 filetype on " 檢測文件的類型

set number              " 顯示行號 set cursorline " 用淺色高亮當前行
"autocmd InsertLeave * se nocul "autocmd InsertEnter * se cul

set ruler               " 在編輯過程當中,在右下角顯示光標位置的狀態行 set laststatus=2 " 顯示狀態欄 (默認值爲 1, 沒法顯示狀態欄)
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
                        " 設置在狀態行顯示的信息 set tabstop=4 " Tab鍵的寬度
set softtabstop=4
set shiftwidth=4        " 統一縮進爲4 set autoindent " vim使用自動對齊,也就是把當前行的對齊格式應用到下一行(自動縮進)
set cindent             " (cindent是特別針對 C語言語法自動縮進) set smartindent " 依據上面的對齊格式,智能的選擇對齊方式,對於相似C語言編寫上有用

set scrolloff=3         " 光標移動到buffer的頂部和底部時保持3行距離 set incsearch " 輸入搜索內容時就顯示搜索結果
set hlsearch            " 搜索時高亮顯示被找到的文本 set foldmethod=indent " 設置縮進摺疊
set foldlevel=99        " 設置摺疊層數 nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> " 用空格鍵來開關摺疊

" 自動跳轉到上次退出的位置 if has("autocmd") au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" 修改配色 end END 複製代碼

添加 ~/.bashrc

cat << END >> ~/.bash_profile

test -s ~/.bashrc && . ~/.bashrc
END
複製代碼

設置經常使用程序別名

cat << END >> ~/.bashrc

alias ll='ls -l'
alias grep='grep --color'
END
複製代碼

設置 git 別名

git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --date=format:'%Y-%m-%d %H:%M:%S' --abbrev-commit"
複製代碼

參考

相關文章
相關標籤/搜索