有些工具和庫可能需要配置環境變數才能正常工作,例如將程式語言的直譯器或編譯器的路徑新增到系統的PATH變數中。
本文以新增g++編譯器為例演示如何新增環境變數
先來認識一下我們的g++編譯器

是的, 他就是一個可執行檔案
那麼該怎麼使用呢?
通常我們在終端中想要執行.exe
檔案我們只需在檔案所在目錄時輸入./a.exe
即可
比如我們進入到g++所在目錄執行g++ -v(其中-v是一個引數,有這個引數他就會顯示g++版本資訊)

但是當我們不在g++檔案所在目錄時就無法使用g++了

但我們仍然可以透過絕對路徑呼叫

那麼為了方便的呼叫我們就需要將其設定成環境變數,這樣的話我們可以在任意目錄下使用g++了
新增環境變數
將g++的絕對路徑新增至環境變數
-
可以搜尋path
-
也可以右鍵
此電腦
,選擇屬性
,找到高階系統設定

- 開啟後點選環境變數

-
在
使用者變數
中選中Path
,點選編輯
,然後新建
將g++所在位置的路徑新增即可,注意,如果新增了多個同名編譯器的路徑,他會預設選擇最上面那個路徑
接下來我們在任何位置都能使用g++了

所以我們想要將某個exe檔案新增到路徑只需要將所在位置路徑新增到環境變數即可