Ubuntu Linux 環境變量
同Windows一樣,Ubuntu Linux系統包含兩類環境變量:系統環境變量和用戶環境變量。系統環境變量對所有系統用戶都有效,用戶環境變量僅僅對當前的用戶有效。
用戶環境變量通常被存儲在下面的文件中:
- ~/.profile
- ~/.bash_profile 或者 ~./bash_login
- ~/.bashrc
上述文件在Ubuntu 10.0以前版本不推薦使用。
系統環境變量一般保存在下面的文件中:
- /etc/environment
- /etc/profile
- /etc/bash.bashrc
/etc/profile和 /etc/bash.bashrc在Ubuntu 10.0版本中不推薦使用。
Ubuntu Linux 環境變量的優先級
- /etc/profile:在登錄時,操作系統定制用戶環境時使用的第一個文件,此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件自動被執行。
- /etc/environment:在登錄時操作系統使用的第二個文件,系統在讀取你自己的profile前,設置環境文件的環境變量。
- ~/.bash_profile:在登錄時用到的第三個文件是.profile文件,每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該文件僅僅執行一次!默認情況下,他設置一些環境變量,執行用戶的.bashrc文件。/etc/bashrc:為每一個運行bash shell的用戶執行此文件.當bash shell被打開時,該文件被讀取.
- ~/.bashrc:該文件包含專用於你的bash shell的bash信息,當登錄時以及每次打開新的shell時,該該文件被讀取。
- /etc/bash.bashrc:當用戶進入shell或桌面系統自動執行的腳本
幾個環境變量的優先級:1>2>3
Ubuntu Linux中設置adb環境變量
- 當前用戶(homer)
在這個文件中加入:export PATH=/home/homer/android-sdk-linux/platform-tools/:$PATH
重啟或再次登陸后生效,如果想立即生效,則執行:source ~/.bashrc
- 超級用戶(root)
su root
vi ~/.bashrc (root默認目錄下的bashrc文件)
在這個文件中加入:export PATH=/home/homer/android-sdk-linux/platform-tools/:$PATH
重啟或再次登陸后生效,如果想立即生效,則執行:source ~/.bashrc
- 全局設置(homer、root、sudo)
1. 實現思路:
在PATH默認的bin目錄下,新建adb的軟鏈接
2. 查看sudo $PATH: echo 'echo $PATH' | sudo sh
/usr/local/sbin:
/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
3. 進入sudo默認PATH:
cd /usr/local/bin/
4. 建立軟鏈接:
sudo
ln -s /home/homer/android-sdk-linux/platform-tools/adb
5. 這樣,在普通用戶(homer)、超級用戶(root)、sudo用戶,都可以直接使用adb命令,因為這些用戶的PATH環境變量都包含了目錄
/usr/local/bin
Ubuntu Linux 無法識別手機
homer@ubuntu:~$ adb devices
List of devices attached
???????????? no permissions
Ubuntu Linux 啟動手機識別
homer@ubuntu:~$ sudo adb kill-serverhomer@ubuntu:~$ sudo adb start-server
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
homer@ubuntu:~$ adb devices
List of devices attached
FM6111131707 device