sudo echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/lubuntu/Tools/android-sdk-linux/platform-tools
adb exists in /home/lubuntu/Tools/android-sdk-linux/platform-tools
adb存在於/ home / lubuntu / Tools / android-sdk-linux / platform-tools中
Then I executed adb start-server:
然后我執行了adb start-server:
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
Then sudo adb install test.apk
然后sudo adb安裝test.apk
sudo: adb: command not found
I have added adb in the environment variable $PATH, but sudo couldn't find it. Why?
我在環境變量$ PATH中添加了adb,但是sudo找不到它。為什么?
5 个解决方案
#1
6
sudo means you're switching to root, and that does not necessarily mean that your environment comes along. That could be dangerous.
sudo意味着你要切換到root,這並不一定意味着你的環境出現了。那可能很危險。
At your risk, add the -E option to inherit the calling environment.
冒風險,添加-E選項以繼承調用環境。
#2
5
The problem is the PATH var is set for that user, and root don't have the aditional PATH entry, so it can't found the program.
問題是為該用戶設置了PATH var,而root沒有aditional PATH條目,因此無法找到該程序。
You should setup adb for root too:
你也應該為root設置adb:
adb Environmental Variables
adb環境變量
Open ~/.bashrc and add the following to the very bottom
打開〜/ .bashrc並將以下內容添加到最底層
export PATH=${PATH}:/tools:/platform-tools
Change to the actual path. ie /home/user/android-sdk-linux Close and re-open your terminal to refresh variables.
將
更改為實際路徑。 ie / home / user / android-sdk-linux關閉並重新打開終端刷新變量。
來自adb設置
If doesn't work, make symbolic links from adb and other binaries to /usr/local/bin
如果不起作用,請將adb和其他二進制文件的符號鏈接創建到/ usr / local / bin
#3
2
Since you are running adb as root in the second example, adb would also have to be on root's path.
由於您在第二個示例中以root身份運行adb,因此adb也必須位於root的路徑上。
#4
2
completely agree with answer of @unwind.
You must not do this using "sudo".
Give it a try without sudo and i guess it would work for you.
Also, you should add the path to folder named "tools" present in the sdk, though its not connected with your problem, but a suggestion.
完全贊同@unwind的回答。你不能使用“sudo”這樣做。嘗試沒有sudo嘗試,我想它會對你有用。此外,您應該將路徑添加到sdk中存在的名為“tools”的文件夾中,盡管它與您的問題無關,但建議。
#5
2
Completely agree.
The problem was the Android Debug Bridge (adb) command line tool that was not linked to the path. After setting it in the path, it worked for me.
問題是沒有鏈接到路徑的Android Debug Bridge(adb)命令行工具。在路徑中設置后,它對我有用。
$ gedit ~/.bashrc
set the path as follows in the .bashrc
在.bashrc中設置如下路徑
export PATH=${PATH}:~/adt-bundle/tools
export PATH=${PATH}:~/adt-bundle/platform-tools