Android Debug Bridge (adb) 命令行工具存在于 $PATH 中,但在 linux 中“找不到命令”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9429183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:47:30  来源:igfitidea点击:

Android Debug Bridge (adb) command line tool exists in $PATH, but "command not found" in linux

androidlinuxadbsudo

提问by Searene

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 install 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 找不到它。为什么?

采纳答案by unwind

sudomeans 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 -Eoption to inherit the calling environment.

请自行承担风险,添加-E继承调用环境的选项。

回答by lamplightdev

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 的路径上。

回答by akkilis

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”的文件夹中,尽管它与您的问题无关,但这是一个建议。

回答by Paulo Fidalgo

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 变量,而 root 没有附加的 PATH 条目,因此无法找到该程序。

You should setup adb for root too:

您也应该为 root 设置 adb:

adb Environmental Variables

adb 环境变量

Open ~/.bashrcand add the following to the very bottom

打开~/.bashrc并将以下内容添加到最底部

export PATH=${PATH}:<sdk>/tools:<sdk>/platform-tools

Change <sdk>to the actual path. ie /home/user/android-sdk-linuxClose and re-open your terminal to refresh variables.

更改<sdk>为实际路径。即/home/user/android-sdk-linux关闭并重新打开您的终端以刷新变量。

from adb setup

亚行设置

If doesn't work, make symbolic links from adb and other binaries to /usr/local/bin

如果不起作用,请创建从 adb 和其他二进制文件到 /usr/local/bin 的符号链接

回答by user2692627

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 调试桥 (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