環境搭建目錄
前提環境
python
selenium
setuptools,pip
通用環境
Homebrew
Node & NPM
Carthage
Appium
Appium Doctor
iOS 環境
Xcode
ios-deploy
ideviceinstaller & libimobiledevice
ios_webkit_debug_proxy
一、前提環境配置
安裝python
下載python進行安裝https://www.python.org/,默認安裝,安裝好之后,打開終端,輸入python,如提示不是內部命令,則將python安裝目錄添加到環境變量Path中。
安裝setuptools,pip
下載setuptools,pip https://pypi.python.org/pypi/setuptools https://pypi.python.org/pypi/pip
打開cmd 進入setuptools解壓目錄,輸入:python setup.py install 進入pip解壓目錄,輸入:python setup.py install 安裝好后,打開終端,輸入pip,如提示不是內部命令,則將python安裝目錄下Scripts目錄添加到環境變量Path中。
安裝selenium
終端輸入pip install Selenium安裝最新版本的selenium。
pip install Selenium 如需安裝指定的版本,則pip install Selenium==版本號。
pip install Selenium==版本號
二、通用環境配置
安裝 Homebrew
Homebrew是一個包管理軟件,它可以使我們更容易地安裝其他一些軟件,終端輸入安裝:
安裝
MacBook-Air ~ % /bin/bash -c "(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
重新安裝
MacBook-Air ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
檢查homebrew是否安裝
MacBook-Air ~ % brew -v
MacBook-Air ~ % brew list //查看已安裝列表
MacBook-Air ~ % brew update //更新Homebrew
如果安裝失敗(網速不行等。。),可以打開網址:http://vip.ytesting.com/q.do?a&id=ff80808172521d8201726a74986f0880 將其內容保存為homebrew.txt,然后終端輸入:
MacBook-Air ~ % /usr/bin/ruby homebrew.txt
注意:此步驟還順帶安裝了Xcode命令行工具(xcode-commaindline-tools)。
安裝 Node & NPM
Node是一個javascript運行時環境,npm是節點包管理器。我們需要這些,因為Appium是一個節點應用程序。在終端中,輸入以下命令(此命令也將安裝npm):
安裝
MacBook-Air ~ % brew install node
查看node版本
MacBook-Air ~ % node -v
重新安裝:
MacBook-Air ~ % brew reinstall node
默認的npm源再國內都很慢,安裝好node之后需要重新配置一個國內源
MacBook-Air ~ % npm config set registry https://registry.npm.taobao.org/
MacBook-Air ~ % npm -v
安裝 Carthage
Carthage是一個依賴管理器,類似于java的maven,WebDriverAgent需要它,終端輸入:
安裝carthage
MacBook-Air ~ % brew install carthage
更新carthage
MacBook-Air ~ % brew upgrade carthage
重新安裝:
MacBook-Air ~ % brew reinstall carthage
安裝完成后檢查一下是否安裝成功
MacBook-Air ~ % carthage version //打印出版本號即表示安裝成功
如果安裝
carthage
出現以下錯誤:Error: An unexpected error occurred during the
brew link
stepThe formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks
原因是
carthage
已經安裝,但是沒有 link 到 brew,還有就是文件夾權限問題,在終端輸入:MacBook-Air ~ % sudo mkdir /usr/local/Frameworks
MacBook-Air ~ % sudo chown $(whoami):admin /usr/local/Frameworks
MacBook-Air ~ % brew link carthage
安裝 Appium(二選1)
Appium(Version 1.13)是一個用于本地、混合和移動web應用程序的開源測試自動化框架。它使用WebDriver協議驅動iOS、Android和Windows mobile應用程序。
方式1:安裝桌面版 appium-server(推薦)
桌面版包含了appium-server,同時也包含一個元素定位器,建議安裝桌面版。
進入官網下載
MacBook-Air ~ % git clone https://github.com/appium/appium-desktop.git
其他版本:進入官網下載1.17.1
方式2:安裝 appium-server 版
1、安裝 appium-server
終端安裝server版輸入:
MacBook-Air ~ % npm install -g appium
默認安裝最新的版本,如果想安裝指定的版本:
MacBook-Air ~ % npm install -g appium@1.7.2
卸載 Appium:
MacBook-Air ~ % npm uninstall -g appium
MacBook-Air ~ % npm cache clean --force
安裝appium client
appium主站上給出的命令是npm install wd 這應該是老版本的安裝方法:
MacBook-Air ~ % npm install wd # get appium client
MacBook-Air ~ % npm wd -v # 檢查是否安裝成功。
推薦下面的方法進行安裝:
安裝python-client
MacBook-Air ~ % git clone git@github.com:appium/python-client.git # 下載python-client
MacBook-Air ~ % cd python-client # 進入python-client目錄
MacBook-Air ~ % python setup.py install # 安裝python-client
安裝成功:
Finished processing dependencies for Appium-Python-Client==0.30 # 表示安裝成功,安裝版本0.30
安裝appium-doctor:
1、安裝appium-doctor
終端運行appium-doctor檢查appium安裝是否成功
MacBook-Air ~ % npm install appium-doctor -g
MacBook-Air ~ % node your-appium-test.js
2、檢查appium安裝版本
appium doctor用來檢查appium的是否成功安裝。手動下載安裝appium doctor的網址在:https://github.com/appium/appium-doctor
MacBook-Air ~ % appium -v # 安裝完成之后輸入appium -v,顯示版本號表示appium server安裝成功
3、啟動appium服務
在終端輸入appium &。輸出下面的信息,則表示appium server啟動成功了。
MacBook-Air ~ % appium &
[1] 965$ [Appium] Welcome to Appium v1.9.1
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
在終端輸入:appium-doctor --ios 檢查 iOS環境環境
其中的 WARN(警告)不用管:
iOS自動化 必要 環境配置沒有問題
配置jdk+Android SDK 環境配置--針對Android
查看所有 必要 配置環境是否成功
打開.bash_profile
MacBook-Air ~ % open .bash_profile
Setting PATH for SDK
export ANDROID_HOME=/Users/用戶名/Library/Android/sdk
export PATH=PATH
export PATH=PATH
Setting PATH for Jdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
export PATH=PATH
export CLASSPATH=.:JAVA_HOME/lib/tools.jar
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
關閉保存后,更新.bash_profile
MacBook-Air ~ % source .bash_profile
在終端輸入:appium-doctor --Android 檢查 Android環境環境
安裝完成后,終端輸入appium-doctor 檢測環境是否成功(查詢結果顯示?表示沒有配置,需要配置,查看需要設置的必要環境)。
安裝appium-doctor,android方面的環境需要:
必選項—— ANDROID_HOME、JAVA_HOME、adb、android、emulator
其中的警告不用管
appium-doctor # 默認安裝路徑:/usr/local/lib/node_modules/appium/node_modules/
IOS自動化環境配置
安裝Xcode和模擬器
啟動Mac應用程序商店并下載/安裝Xcode(Version 13.1)。安裝之后,啟動Xcode并選擇 Xcode > Preferences > Components 來安裝可能想要測試的模擬器。
安裝Command Line Tools
默認是不會安裝Command Line Tools的,Command Line Tools是在Xcode中的一款工具,可以在命令行中運行C程序。為了配置appium環境,我們需要安裝Xcode Command Line Tools。
官網下載
下載完成后,雙擊已下載的 .dmg 進行安裝
檢驗 Command Line Tools 是否安裝成功
方法一:
MacBook-Air ~ % xcode-select --install # 查看是否安裝
xcode-select: error: command line tools are already installed, use "Software Update" to install updates(錯誤:命令行工具已經安裝,請使用“軟件更新”安裝更新)
方法二:打開Xcode,創建一個新的項目,在OSX下面選擇Application,如果右側出現Command line tool圖標,表示已經安裝成功。
方法三:打開XCode 新建工程,如果安裝了,在新建窗口可以看到
安裝完成后,在終端中輸入以下命令來查看安裝版本:
MacBook-Air ~ % xcodebuild -version
Xcode 11.6
如果已經安裝過xcode,appium-doctor提示未安裝,則運行命令即可:
MacBook-Air ~ % sudo xcode-select -r
Tips
:
查看已啟動的模擬器udid
xcrun simctl list | grep '(Booted)'
列出所有設備,包括真機、模擬器、mac
instruments -s devices
錄像功能
xrecord --quicktime --list
xrecord --quicktime --name="iPhone" --out="/Users/blah/video/iphone.mp4" --force
安裝 libimobiledevice & ideviceinstaller
libimobiledevice
是一個跨平臺的軟件庫,支持 iPhone?, iPod Touch?, iPad? and Apple TV? 等設備的通訊協議。不依賴任何已有的私有庫,不需要越獄。應用軟件可以通過這個開發包輕松訪問設備的文件系統、獲取設備信息,備份和恢復設備,管理 SpringBoard 圖標,管理已安裝應用,獲取通訊錄、日程、備注和書簽等信息,使用 libgpod 同步音樂和視頻。 ideviceinstaller
是一個與iOS設備的installation_proxy交互的工具,允許安裝、升級、卸載、存檔、還原和列舉已安裝或存檔的app。此工具用于在真機上運行測試,默認是都安裝的。
MacBook-Air ~ % brew install libimobiledevice --HEAD # 安裝最新的更新
MacBook-Air ~ % brew reinstall libimobiledevice # 重新安裝
MacBook-Air ~ % brew install ideviceinstaller # 用于查看bundleid
MacBook-Air ~ % brew reinstall ideviceinstaller # 重新安裝
如果安裝時遇到: “invalid active developer path” 則運行:
MacBook-Air ~ % xcode-select --install
MacBook-Air ~ % sudo xcode-select -r
可能出現的問題
dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from:
/usr/local/opt/libimobiledevice/lib/libimobiledevice.6.dylib Reason: image not found
如果遇到如上錯誤,則先卸載ideviceinstaller 和 libimobiledevice
MacBook-Air ~ % brew uninstall ideviceinstaller
MacBook-Air ~ % brew uninstall libimobiledevice
然后再重安裝即可
安裝 ios-deploy
ios-deploy
同樣是一個不需要用Xcode安裝和調試應用的命令行工具。需要一個有效的開發者證書,需要 Xcode 7以上的版本。終端輸入命令進行安裝:
MacBook-Air ~ % brew install ios-deploy # 安裝命令
MacBook-Air ~ % brew reinstall ios-deploy # 重新安裝
MacBook-Air ~ % brew upgrade ios-deploy # 更新命令
安裝 ios_webkit_debug_proxy
Appium使用ios_webkit_debug_proxy這個工具在真機上訪問web view。在終端中,運行以下命令:
MacBook-Air ~ % brew install ios-webkit-debug-proxy # 安裝命令
MacBook-Air ~ % brew reinstall ios-webkit-debug-proxy # 重新安裝
至此iOS環境搭建完畢?。?!只適用于模擬器,真機的話還需要配置。
iOS真機調試環境配置
編譯webagentrunner項目,安裝到被測真實設備上
查看appium的安裝位置,正常npm安裝的位置應該在/usr/local/bin/appium下
MacBook-Air ~ % which appium
/usr/local/bin/appium (命令版安裝)
命令行安裝的appium一般安裝在/usr/local/bin/appium
下,WebDriverAgent將會在路徑:/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/
下;如果是桌面版
的,WebDriverAgent的路徑是:ls /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent
命令行版
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/
桌面版
MacBook-Air ~ % cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent
首先查看路徑(/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
)下有沒有WebDriverAgent.xcodeproj
(有的話跳過下邊,直接用Xcode打開即可)
2)如果/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent 沒有WebDriverAgent.xcodeproj存在,則打開終端運行如下命令搭建項目:
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/
MacBook-Air ~ % mkdir -p Resources/WebDriverAgent.bundle
MacBook-Air ~ % ./Scripts/bootstrap.sh -d
然后用Xcode 打開
WebDriverAgent.xcodeproj
,在 “Signing&Capabilities” 下將 WebDriverAgentLib
和 WebDriverAgentRunner
設置成 “Automatically manage signing” 并在 “Team” 中選擇你的開發團隊 ;新用戶第一次需要創建Team團隊
個人證書調試失敗
Failed to register bundle identifier.
The app identifier "com.facebook.WebDriverAgentRunner" cannot be registered to your development team because it is not available. Change your bundle identifier to a unique string to try again.
需要手動更改目標的bundle id
,方法是進入“Build Settings”選項,更改“Product bundle Identifier”的值使Xcode將接受,默認為com.facebook.WebDriverAgentRunner
,你需要改成不一樣的,如:io.automation.WebDriverAgentRunner
返回 “Signing&Capabilities” 選項,看到對于文件WebDriverAgentRunner的配置文件已經創建成功了
解決??問題
真機測試
最后,build項目: 通過Xcode獲取udid:
利用ios-deploy獲取,其他參考上邊的介紹
MacBook-Air ~ % ios-deploy -c
命令行進入到WDA項目目錄
MacBook-Air ~ % cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
將WDA安裝到被測手機上,并測試該應用
MacBook-Air ~ % xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=<測試機的udid>' test
報錯:
error: No profiles for 'io.uitest.WebDriverAgentRunner.xctrunner' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'io.uitest.WebDriverAgentRunner.xctrunner'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'WebDriverAgentRunner' from project 'WebDriverAgent')報這個錯是因為沒有接入相關的設備到MAC上,只要設備接入,并通過XCode菜單:Product->Destnation->"Select Devices"選中要連接的設備就行。
XCode:
Product->Destination->"Select your iphone"
Product->Scheme->"Select WebDriverAgentRunner"
Product -> Test
注意:運行Test之前,手機先解鎖再通過USB線連接到電腦。
運行完"Test",如果遇到這個報錯:
運行報錯:
/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj User-supplied CFBundleIdentifier value 'com.facebook.wda.lib' in the Info.plist must be the same as the PRODUCT_BUNDLE_IDENTIFIER build setting value 'com.facebook.WebDriverAgentLib'.
解決方案:
運行報錯:
/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.h:16:9: 'CocoaAsyncSocket/GCDAsyncSocket.h' file not found
解決:進入appium-webdriveragent目錄,重新執行:
MacBook-Air % cd /usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent
MacBook-Air appium-webdriveragent % sh ./Scripts/bootstrap.sh
再次執行Product -> Test,彈出密鑰授權彈窗,輸入密鑰(多次輸入密鑰,直到彈窗消失)
最后報錯:Command CodeSign failed with a nonzero exit code
解決方案---通過終端命令:MacBook-Air appium-webdriveragent % xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=000-000080E' test
執行中會彈出密鑰彈窗,多次輸入密鑰,直到彈窗消失
最后機上可以看到一個沒有圖標的 WebDriverAgentRunner.app 應用,進入設置 -》通用 -》設備管理 -》點擊 開發者app下面的證書 -》點擊“第一個藍色字體信任按鈕” -》點擊信任,再重新執行項目即可正常連接
xcode點擊??直接運行:
再次報錯:
/usr/local/lib/node_modules/appium/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj User-supplied CFBundleIdentifier value 'com.facebook.wda.runner' in the Info.plist must be the same as the PRODUCT_BUNDLE_IDENTIFIER build setting value 'io.uitest.WebDriverAgentRunner'.
解決方案:
最終看到這樣輸出就是成功了:
Test Suite ‘All tests’ started at 2017-01-23 15:49:12.585
Test Suite ‘WebDriverAgentRunner.xctest’ started at 2017-01-23 15:49:12.586
Test Suite ‘UITestingUITests’ started at 2017-01-23 15:49:12.587
Test Case ‘-[UITestingUITests testRunner]’ started.
t = 0.00s Start Test at 2017-01-23 15:49:12.588
t = 0.00s Set Up
驗證是否安裝成功,確保手機和電腦連接同一個WiFi(同一局域網內),可以不設置這些內容:
export DEVICE_URL='http://<device IP>:8100'
export JSON_HEADER='-H "Content-Type: application/json;charset=UTF-8, accept: application/json"'
curl -X GET DEVICE_URL/status
直接在手機瀏覽器中輸入這個地址http://127.0.0.1:8100/status返回一個json串即表明連接成功
安裝成功后運行如果遇到這樣的錯誤:
2017-01-24 09:02:18.358 xcodebuild[30385:339674] Error Domain=com.apple.platform.iphoneos Code=-12 "Unable to launch com.apple.test.WebDriverAgentRunner-Runner" UserInfo={NSLocalizedDescription=Unable to launch com.apple.test.WebDriverAgentRunner-Runner, NSUnderlyingError=0x7fa839cadc60 {Error Domain=DTXMessage Code=1 "(null)" UserInfo={DTXExceptionKey=The operation couldn’t be completed. Unable to launch com.apple.test.WebDriverAgentRunner-Runner because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user. : Failed to launch process with bundle identifier 'com.apple.test.WebDriverAgentRunner-Runner'}}}
2017-01-24 09:02:18.358 xcodebuild[30385:339674] Error Domain=IDETestOperationsObserverErrorDomain Code=5 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted}
Testing failed:
Test target WebDriverAgentRunner encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted)
至此iOS真機運行環境mac端配置完畢
手機端設置
進入設置,開發者選項,允許UIautomator
Tips:
真機運行務必添加這兩個參數到capabilities:
{
#xcodeOrgId 類似:TEST INTERNATIONAL
"xcodeOrgId": "<Team ID>",
#xcodeSigningId 是一個由Apple生成的唯一的10個字符的字符串,類似 6387P24J3L
"xcodeSigningId": "iPhone Developer"
}
這兩個字段獲取方式:
xcodeOrgId
: 開發者組織代碼,是一串唯一的10位隨機字符串。查找方式:打開keychain,找到蘋果開發者對應的證書,點進去,找到Organizational Unit這項,對應的字符串就是了
xcodeSigningId
:直接填 iPhone Developer
真機手動配置補充
udid就是設備唯一識別碼了,查看方式參考上文,如果只連接了一臺設備可以設置為auto
理想情況下,appium會自動注冊并編譯,但是如果有出現編譯失敗報錯誤碼65的現象一般是由于找不到指定的開發者證書,需要我們手動配置一下,配置之后再手動編譯一次,下次再運行的時候基本就可以了
第一次在手機構建webdriveragent應用時,xcode需要訪問keychain以獲取證書,輸入當前mac用戶的登錄密碼,然后點擊 allow all
即可,如果連續彈出多次對話框就多次點擊 allow all
附錄
ios-deploy使用命令參考
安裝應用
ios-deploy -c # 查看當前鏈接的設備,獲取udid
xxx.app為 Xcode 編譯后的應用安裝包路徑
ios-deploy --id [udid] --bundle [xxx.app] # 給指定設備安裝應用,udid是蘋果設備唯一識別碼
卸載應用
ios-deploy --id [udid] --uninstall_only --bundle_id [bundleId] # 給指定連接的設備卸載應用
查看設備已安裝的應用
ios-deploy --id [udid] --list_bundle_id # 查看設備安裝的所有應用,包括系統應用和第三方應用
ios-deploy --id [udid] --exists --bundle_id # 指定設備檢查指定應用是否已經安裝
idevice命令用法參考
獲取設備的udid的幾種方法
idevice_id --list # 略寫為 -l 顯示當前所連接設備的 udid
idevice_id -l # 顯示當前所連接的設備[udid],包括 usb、WiFi 連接
instruments -s devices # 列出設備包括模擬器、真機及 mac 電腦本身
ideviceinfo # 可以在返回的數據中找到 udid
另外蘋果手機 safari打開網址http://fir.im/udid 就看到了
安裝應用
xxx.ipa為應用在本地的路徑
ideviceinstaller -i apppath # 安裝apppath下的app
ideviceinstaller -u [udid] -i [xxx.ipa] # 給指定連接的設備安裝應用
卸載應用
bundleId為應用的包名
ideviceinstaller -u [udid] -U [bundleId] # 給指定連接的設備卸載應用
查看設備已安裝的應用
ideviceinstaller -l #列出手機上所有用戶安裝的app
運行某個app
idevicedebug run 'APP_BUNDLE_ID' # 可以直接launch某個app,當然,這個app必須是你通過development證書build到手機上的才行
ideviceinstaller -u [udid] -l # 指定設備,查看安裝的第三方應用
ideviceinstaller -u [udid] -l -o list_user # 指定設備,查看安裝的第三方應用
ideviceinstaller -u [udid] -l -o list_system # 指定設備,查看安裝的系統應用
ideviceinstaller -u [udid] -l -o list_all # 指定設備,查看安裝的系統應用和第三方應用
獲取設備信息
ideviceinfo -u [udid] # 指定設備,獲取設備信息
ideviceinfo -u [udid] -k DeviceName # 指定設備,獲取設備名稱:iPhone6s
idevicename -u [udid] # 指定設備,獲取設備名稱:iPhone6s
ideviceinfo -u [udid] -k ProductVersion # 指定設備,獲取設備版本:10.3.1
ideviceinfo -u [udid] -k ProductType # 指定設備,獲取設備類型:iPhone8,1
ideviceinfo -u [udid] -k ProductName # 指定設備,獲取設備系統名稱:iPhone OS
其他系統文件信息
idevicescreenshot # 截圖
ideviceinfo # 獲取設備所有信息
idevicesyslog # 獲取設備日志
idevicecrashreport -e test # 獲取設備 crashlog,test 是文件夾需新建
idevicediagnostics restart # (shutdown、sleep)管理設備狀態 - 重啟、關機、睡眠等
安裝 JDK(android自動化)
下載 Java jdk ,按步驟安裝,安裝完成后需要在.bash_profile設置 JAVA_HOME ,設置之前你可以通過下邊的命令查看Java的安裝路徑,terminal輸入:
/usr/libexec/java_home --v
輸出路徑:
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
通過vim 編輯.bash_profile文件,終端輸入:
vim ~/.bash_profile
按 i鍵進入編輯模式,移動到最下邊加入如下兩行(路徑為之前查看的):
[改為你自己的java_home路徑]
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home
export PATH=PATH
添加后按 Esc按鍵,輸入:wq保存并退出編輯。輸入使其生效(或重啟終端):
添加后按 Esc按鍵,輸入:wq保存并退出編輯。輸入使其生效(或重啟終端):
source ~/.bash_profile