小結(jié)
本篇文章是對上一篇文章《MacOS的小結(jié)及終端shell的選擇和相關(guān)配置全過程(zsh+iTerm2+powerline全解)》的一些拓展和總結(jié)档叔,對于相關(guān)問題的詳細(xì)解釋和拓展點(diǎn)的標(biāo)注咬扇。本篇文章和上一篇文章一樣立足于轉(zhuǎn)換開發(fā)工具(windows->Ubuntu->macOs)之后相關(guān)快速上手問題突委,讓大家在短時(shí)間內(nèi)快速掌握一些技巧炬丸、提高效率、快速開發(fā)。mac的一些有點(diǎn)我在上篇文章已經(jīng)做過很多介紹,但是其中的一些優(yōu)點(diǎn)的運(yùn)用還是沒有寫全介牙,本篇文章將在以下幾點(diǎn)進(jìn)行詳細(xì)介紹。
關(guān)鍵字:Homebrew簡述澳厢,python2环础、python3重裝。python開發(fā)環(huán)境搭建剩拢,虛擬環(huán)境安裝线得。
一、Homebrew簡述及安裝
為什么要homebrew徐伐?
相信很多人在接觸蘋果之后見到了homebrew并不知道這是個(gè)什么東西框都,首先看一段代碼
sudo apt-get install [軟件1][軟件2][軟件3]
對于常常接觸linux的同學(xué)們這段代碼再熟悉不過了,沒錯(cuò)就是ubuntu用來安裝軟件的命令呵晨。好了,既然提起了熬尺,而且本次專題的主題就是分析并且解釋這些摸屠,那下面讓我們詳細(xì)來看一下。
首先對于linux內(nèi)核來說粱哼,安裝包的常見格式有rpm包和deb包季二。
rpm包主要應(yīng)用在RedHat系列包括 Fedora等發(fā)行版的Linux系統(tǒng)上,
deb包主要應(yīng)用于Debian系列包括現(xiàn)在比較流行的Ubuntu等發(fā)行版上揭措。
對于這兩種格式的安裝包來說要引入另一個(gè)概念那就是yum和apt-get胯舷,
yum可以用于運(yùn)作rpm包,例如在Fedora系統(tǒng)上對某個(gè)軟件的管理:
安裝:yum install <package_name>
卸載:yum remove <package_name>
更新:yum update <package_name>
apt-get可以用于運(yùn)作deb包绊含,例如在Ubuntu系統(tǒng)上對某個(gè)軟件的管理:
安裝:apt-get install <package_name>
卸載:apt-get remove <package_name>
更新:apt-get update <package_name>
所以在當(dāng)我們使用macOs時(shí)apt-get這個(gè)命令是找不到的桑嘶。這樣就引入了另外一個(gè)名詞:Homebrew好了,知道你們又要說我廢話連篇躬充,可是我還是要說逃顶,而且要詳細(xì)的做一些介紹和解釋,畢竟這才是這篇文章的目的所在充甚。
想必各位程序員大大早已經(jīng)不是在appstore去搜索軟件安裝以政,而是打開終端炫酷的打入代碼,好了伴找,安裝完畢盈蛮。可是究竟這一做法的優(yōu)勢在于什么技矮,難道真是動(dòng)作之騷抖誉?不不不不殊轴,對于brew來說,本來就是專門為macOs提供的missing package的manage寸五,他是基于ruby和git來實(shí)現(xiàn)的梳凛,所有相關(guān)軟件的安裝都是來源于對應(yīng)的官方網(wǎng)站,所以優(yōu)點(diǎn)自來梳杏,對于appstore的軟件來說擁有了相關(guān)的認(rèn)證和權(quán)限韧拒,安裝時(shí)的速度和拓展當(dāng)然不如homebrew了。https://sspai.com/post/32857十性,下面這篇文章介紹的更加詳細(xì)叛溢,大家可以看一下。
安裝
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Homebrew是可以安裝在任何未知的劲适,在很多教程中楷掉,是直接用ruby未指定地址去安裝的,但是建議安裝到/usr/bin/下霞势,相關(guān)原因可以參考一下官方文檔 https://docs.brew.sh/FAQ.html
好了接下來我們安裝軟件只需要用到命令
brew install [軟件名]
更新homebrew庫
brew update
卸載
brew uninstall [軟件名]
更新
brew upgrade
查看安裝軟件列表
brew list
查看安裝路徑
brew --cache
二烹植、python2、python3
直接
brew install python2
brew install python3
在這里說明的是在mac上原裝是帶有python2的之所以在這里重新安裝是因?yàn)镠omebrew的安裝路徑的問題愕贡,在后期安裝相關(guān)拓展時(shí)會(huì)用到pip草雕,而pip在安裝時(shí)會(huì)指定安裝到原來的python2下,如果這樣在重寫終端配置文件不管是bash_profile固以,還是zshrc時(shí)都會(huì)出現(xiàn)問題配置不成功墩虹。
三、安裝mongodb
brew instal mongodb
安裝成功后會(huì)出現(xiàn)如下代碼
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
里面說明了如何啟動(dòng)mongodb憨琳,下面我們配置系統(tǒng)環(huán)境變量诫钓,打開zshrc配置文件(用bash的直接換為~/.bash_profile)
open ~/.zshrc
追加后關(guān)閉
##mongodb系統(tǒng)變量路徑
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
##
修改后別忘了編譯配置文件
source ~/.zshrc
這樣下次可以通過mongod命令直接開啟mongodb了,
#敲入命令開啟mongodb
mongod
#重開終端敲入進(jìn)入mongodb
mongo
三篙螟、安裝虛擬環(huán)境
在Ubuntu上這直接敲入mkvirtualenv [虛擬環(huán)境名字] 是可以直接創(chuàng)建虛擬環(huán)境的菌湃,可是在macos終端中缺是一個(gè)未知的命令,原因就是我們也需要去安裝
安裝 virtualenv
sudo pip3 install virtualenv
創(chuàng)建虛擬環(huán)境
virtualenv env1
安裝virtualenvwrapper
virtaulenvwrapper是virtualenv的擴(kuò)展包遍略,可以更方便地新增慢味,刪除,復(fù)制墅冷,切換虛擬環(huán)境纯路。
sudo easy_install virtualenvwrapper
創(chuàng)建文件夾workspaces存放虛擬環(huán)境
mkdir ~/workspaces
cd ~/workspaces
打開終端shell配置文件寫入配置路徑
open ~/.zshrc
追加
#虛擬環(huán)境路徑
export WORKON_HOME=~/workspaces
source /usr/bin/virtualenvwrapper.sh
編譯
source ~/.zshrc
好了這樣就可以使用虛擬環(huán)境的命令了
創(chuàng)建虛擬環(huán)境
mkvirtualenv [虛擬環(huán)境名字]
列出所有虛擬環(huán)境
workon
#或者
lsvirtualenv -b
進(jìn)入虛擬環(huán)境
workon [虛擬環(huán)境名字]
退出虛擬環(huán)境
deactivate
**刪除虛擬環(huán)境
rmvirtualenv [虛擬環(huán)境名字]
安裝好虛擬環(huán)境就可以進(jìn)入相對應(yīng)的虛擬環(huán)境安裝必備的例如scrapy,flask寞忿,django驰唬,Numpy......的包了。
四、安裝mysql數(shù)據(jù)庫
之前試過直接去用Homebrew安裝叫编,但是安裝成功后在mac的系統(tǒng)偏好設(shè)置中找不到mysqlserver辖佣,在未配置環(huán)境變量路徑時(shí)只能通過找到安裝路徑中的mysql然后命令行啟動(dòng)mysql,特別麻煩搓逾。特此記錄這一個(gè)坑卷谈,防止大家掉坑。
安裝
打開官網(wǎng) : [http://www.mysql.com/downloads/]
(http://www.mysql.com/downloads/) 進(jìn)入, 點(diǎn)擊下方的DOWNLOADS : MySQL Community Server
現(xiàn)在完成后一路確定安裝霞篡,在彈出一個(gè)MYSQL Installer提示框的時(shí)候一定打開備忘錄復(fù)制粘貼記下彈出框的密碼(這步很重要世蔗,大家一定要把密碼記下來)
打開mysql服務(wù)
mac的系統(tǒng)偏好設(shè)置最左下角開啟mysql
將mysql加入到系統(tǒng)環(huán)境變量
打開zshrc追加
PATH=$PATH:/usr/local/mysql/bin
關(guān)閉后source編譯
進(jìn)入mysql
mysql -u root -p
直接復(fù)制剛才粘貼的隨機(jī)代碼(密碼是隱藏的,光標(biāo)不移動(dòng))
修改密碼
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
mysql就配置完畢了朗兵。
通篇總結(jié)
對于在macOs的終端執(zhí)行命令類的拓展污淋,需要打開相應(yīng)的shell對應(yīng)的配置文件進(jìn)行添加路徑操作,bash對應(yīng)的是/.bash_profile,zsh對應(yīng)的是/.zshrc余掖。在修改后別忘了source進(jìn)行編譯才能生效寸爆。從Ubuntu轉(zhuǎn)到mac的同學(xué),如果遇到在終端中敲入命令失效未找到的情況請?jiān)诎惭b相應(yīng)的插件后進(jìn)入相對應(yīng)的配置文件中系統(tǒng)環(huán)境變量中的路徑配置妥善盐欺。
下面附上我的zsh的配置文件自己配置的都有注釋解釋赁豆,希望能讓大家更深一步的理解。
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
##mysql配置系統(tǒng)路徑
PATH=$PATH:/usr/local/mysql/bin
##
# Path to your oh-my-zsh installation.
##zshshell配置地址
export ZSH=$HOME/.oh-my-zsh
##關(guān)鍵字高亮
source $ZSH/oh-my-zsh.sh
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
export CLICOLOR=1
export TERM=xterm-256color
##前綴名顯示
#export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '
##mongodb系統(tǒng)變量路徑
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
##
##python虛擬環(huán)境環(huán)境變量
export WORKON_HOME=~/workspaces
source /usr/local/bin/virtualenvwrapper.sh
##
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel9k/powerlevel9k"
# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array have no effect
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
zsh-autosuggestions
)
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
##zsh中加入powerline美化
. /usr/local/lib/python3.7/site-packages/powerline/bindings/zsh/powerline.zsh
本篇文章對各路安裝方法進(jìn)行總結(jié)和篩選冗美,對于別人的方法和官方的文檔進(jìn)行了總結(jié)和篩選魔种,我在安裝和上手中掉過很多坑,希望這篇文章和上一篇文章《MacOS的小結(jié)及終端shell的選擇和相關(guān)配置全過程(zsh+iTerm2+powerline全解)》能幫助更換操作系統(tǒng)的童鞋們快速上手mac并快速高效的進(jìn)入到python開發(fā)中墩衙。
peterp
July,2018