尝试将 adb 添加到 PATH 变量 OSX
我正在尝试为 android 进行开发,我想将 adb
添加到我的 PATH
中,以便我可以非常轻松地启动它。由于某种原因,我之前添加过目录,adb
不想被发现。这非常令人沮丧。以前有其他人遇到过这个问题吗?
我创建了一个文件 .profile
并向其中添加了以下内容。
export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/platform-tools/
export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/tools
当我检查环境路径时,我看到以下内容:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools
所以我知道它已添加到我的 PATH 变量中。现在,当我尝试运行 adb
时,我发现它没有找到。
-bash: ./adb: No such file or directory
这是非常非常令人沮丧的。会不会是权限的问题?有人在 OSX 和 Android 上遇到过这个问题吗?
I am trying to develop for android and I want to add the adb
to my PATH
so that I can launch it really easily. I have added directories before by for some reason adb
does not want to be found. This is very frustrating. Has anyone else had this problem before?
I created a file .profile
and added the following to it.
export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/platform-tools/
export PATH = ${PATH}:/Users/simon/Libs/android-sdk-mac_x86/tools
When I check my environment path I see the following:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Libs/android-sdk-mac_x86/tools:/Libs/android-sdk-mac_x86/platform-tools
So I know that it is added to my PATH
variable. Now when I try to run adb
I get that it is not found.
-bash: ./adb: No such file or directory
This is very very frustrating. Could it be a problem with permissions? Has anyone had this problem with OSX and Android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
每次登录时添加到 PATH
Total control version:
在终端中,导航到主目录
创建文件 .bash_profile
使用 TextEdit
将行插入 TextEdit
保存文件并重新加载文件
检查 adb 是否设置到路径中
One liner version
回显您的导出命令并将输出重定向到附加到 .bash_profile 文件并重新启动终端。 (尚未验证这一点,但应该有效)
Add to PATH for every login
Total control version:
in your terminal, navigate to home directory
create file .bash_profile
open file with TextEdit
insert line into TextEdit
save file and reload file
check if adb was set into path
One liner version
Echo your export command and redirect the output to be appended to .bash_profile file and restart terminal. (have not verified this but should work)
替代方案:以简单的方式安装 adb
如果您不想担心路径或手动更新 adb,您可以使用 homebrew< /a> 相反。
brew 桶安装 android-platform-tools
Alternative: Install adb the easy way
If you don't want to have to worry about your path or updating adb manually, you can use homebrew instead.
brew cask install android-platform-tools
你为什么要尝试运行“./adb”?这完全跳过路径变量,只在当前目录中查找“adb”。尝试运行“adb”。
编辑:你的路径看起来错误。你说你明白
你错过了 /Users/simon 部分。
另请注意,如果您同时拥有 .profile 和 .bash_profile 文件,则仅执行后者。
Why are you trying to run "./adb"? That skips the path variable entirely and only looks for "adb" in the current directory. Try running "adb" instead.
Edit: your path looks wrong. You say you get
You're missing the /Users/simon part.
Also note that if you have both .profile and .bash_profile files, only the latter gets executed.
在我的 Macbook Pro 上,我已将导出行添加到 ~/.bash_profile,而不是 .profile。
例如
On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.
e.g.
只要有人在使用 Android Studio 时发现这篇 SO 帖子,其中包含的 SDK 是应用程序包的一部分(在 Mac OSX 上)。
正如 @davecaunt 和 @user1281750 所指出的,但将以下行插入 .bash_profile
Just encase anyone finds this SO post when using Android Studio which includes the SDK has part of the App package (on Mac OSX).
So as @davecaunt and @user1281750 noted but insert the following line to .bash_profile
MAC 的答案应该是:
使用以下命令打开您的 bash_profile:
open ~/.bash_profile
如果基本配置文件不存在,请使用以下命令创建一个新文件:
touch .bash_profile
然后重复第 1 阶段。 p>添加以下行:
export PATH= /Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH
重新启动您的 bash 窗口并通过输入
adb shell
进行测试祝你好运! :-)
The answer for MAC should be:
Open your bash_profile with the following commands:
open ~/.bash_profile
In case base profile file doesn't exist, create a new one with the following command:
touch .bash_profile
then repeat phase 1.Add the following line:
export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH
Restart your bash window and test by typing
adb shell
Good luck! :-)
在终端中,导航到主目录
source ~/.bash_profile 非常重要
检查 adb 是否设置为路径
现在应该没问题了。
In your terminal, navigate to home directory
source ~/.bash_profile is very important
check if adb was set into path
It should be fine now.
我使用 zsh 和 Android Studio。我对 Android SDK 路径使用变量,并在文件
~/.zshrc
中进行配置:注意:确保指定路径周围不要包含单引号或双引号。如果这样做,它将不起作用。
I use zsh and Android Studio. I use a variable for my Android SDK path and configure in the file
~/.zshrc
:Note: Make sure not to include single or double quotes around the specified path. If you do, it won't work.
Android Studio v1.2 在这个路径中安装 adb 工具:
所以它是这样的:
adb version
并期望错误输出touch ~/.bash_profile
open ~/.bash_profile
source ~/.bash_profile
adb version
并期望输出祝你好运!
Android Studio v1.2 installs the adb tool in this path:
So it goes like this:
adb version
and expect an error outputtouch ~/.bash_profile
open ~/.bash_profile
source ~/.bash_profile
adb version
and expect an outputGood luck!
您似乎仍在尝试使用
./adb
执行adb
。这要求 shell 在当前工作目录中运行名为adb
的程序。尝试仅使用
adb
而不使用./
。It appears that you're still trying to execute
adb
with./adb
. That asks the shell to run the program namedadb
in the current working directory.Try just
adb
without./
.为了使终端始终具有文件
~/.bashrc
并放置您希望使用的路径,请添加:其中 XXX 是您希望使用的路径。
对于 adb,这是我使用的:(
其中“user”是我的用户名)。
In order to make the terminal always have the file
~/.bashrc
and there put the path you wish to use, by adding:where XXX is the path that you wish to use.
for adb, here's what i use:
(where "user" is my user name).
第二个解决方案解释如下。但是当我关闭终端时,我在路径变量中所做的更改就会丢失。因此我更喜欢第一种方式!
2nd solution is explained below. But when i close the terminal the change which i made in path variable gets lost. Thus i prefer the first way!
如果您是 Catalina 用户,请按照此
确保位于主目录中
cd~
要保留 PATH 更改并防止其在关闭终端应用程序后被清理,您需要将变量保留在 Catalina 的 zshrc 文件中
触摸.zshrc
使用文本编辑器打开它
打开-e.zshrc
插入下面的命令将 ADB 添加为 PATH 变量(用您自己的用户名替换用户名)
导出 PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/
保存文件并关闭 TextEditor 应用程序。返回终端应用程序,插入以下内容以获取文件
源代码.zshrc
就完成了!我们来测试一下是否成功
adb版本
您应该期待类似的内容
Android 调试桥版本 1.0.41
版本31.0.2-7242960
安装为 /Users/用户名/Library/Android/sdk/platform-tools//adb
If you are Catalina user follow this
Make sure to be in the Home directory
cd ~
To persist PATH changes and prevent it to be cleaned up after closing the Terminal app, you need to keep the variables in the zshrc file for Catalina
touch .zshrc
Open it with the TextEditor
open -e .zshrc
Insert the command below to add ADB as PATH variable (replace username with your own)
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
Save the file and close the TextEditor app. Back to the Terminal app, insert the following to source the file
source .zshrc
And you’re done! Let’s test if it was successful
adb version
You should expect something like
Android Debug Bridge version 1.0.41
Version 31.0.2-7242960
Installed as /Users/username/Library/Android/sdk/platform-tools//adb
我将
export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/
添加到.bash_profile
和.profile 以确保其有效。但它仍然不起作用,然后我查看了 sarnold 的提示关于重新启动终端,它就像一个魅力。
每当我必须运行
adb
时,它节省了我每次将其添加到PATH
中的时间。谢谢你们。
I added
export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/
into both places.bash_profile
and.profile
to make sure it works. Still it wasn't working and then I looked at sarnold's tip about restarting terminal and it worked like a charm.It saved my time of adding every time this into the
PATH
whenever I had to runadb
.Thank you guys.
如果任何人似乎无法到达 .bash_profile 文件来获取任何新路径并且您在该文件中有其他命令(例如别名命令),则尝试移动 PATH 语句到文件顶部。
这是唯一对我有用的事情。它起作用的原因是因为我的别名命令中有一些拼写错误,并且显然该文件会抛出错误并在遇到问题时退出。这就是我的 PATH 语句没有运行的原因。把它移到顶部就让它先运行。
If anyone can't seem to get there
.bash_profile
file to take any new Paths AND you have other commands in that file (like alias commands) then try moving the PATH statements to the top of the file.That is the only thing that worked for me. The reason it worked was because I had some typos in my alias commands and apparently this file throws an error and exits if it runs into a problem. So that is why my PATH statements weren't being run. Moving it to the top just let it run first.
在 bash 配置文件中
只需添加 -
然后在终端运行 -
In bash profile
just add -
and then in terminal run -
所有答案都写得很好并且很有帮助,但我想提一件事。在将路径变量添加到
.bash_profile
之前,请检查您的默认 shell。因为我在
.bash_profile
文件中设置路径变量,但我的默认 shell 是zsh
这就是为什么我每次都必须运行source ~/.bash_profile
在使用 adb 命令之前。因此,首先检查您的默认 shell:
/bin/bash
那么您应该在中设置路径变量.bash_profile
/bin/zsh
那么你应该在.zshrc
中设置路径变量,这是我的路径变量:
All answers are well written and helpful but there is one thing that I want to mention. Before adding path variable to
.bash_profile
kindly check your default shell.Because i was seting path variable in
.bash_profile
file but my default shell waszsh
that's why i have to runsource ~/.bash_profile
each time before using adb command.So first check your default shell:
/bin/bash
then you should set path variable in.bash_profile
/bin/zsh
then you should set path variable in.zshrc
And here is my path variable: