[英]Trying to add adb to PATH variable OSX
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.我正在尝试为 android 进行开发,并且我想将
adb
添加到我的PATH
以便我可以非常轻松地启动它。 I have added directories before by for some reason adb
does not want to be found.我之前添加了目录,由于某种原因
adb
不想被发现。 This is very frustrating.这非常令人沮丧。 Has anyone else had this problem before?
以前有没有其他人遇到过这个问题?
I created a file .profile
and added the following to it.我创建了一个文件
.profile
并向其中添加了以下内容。
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.所以我知道它已添加到我的
PATH
变量中。 Now when I try to run adb
I get that it is not found.现在,当我尝试运行
adb
时,我发现它找不到。
-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?
有人对 OSX 和 Android 有这个问题吗?
Total control version :总控制版本:
in your terminal, navigate to home directory在您的终端中,导航到主目录
cd
光盘
create file .bash_profile创建文件 .bash_profile
touch .bash_profile
触摸 .bash_profile
open file with TextEdit用 TextEdit 打开文件
open -e .bash_profile
打开 -e .bash_profile
insert line into TextEdit在 TextEdit 中插入行
export PATH=$PATH:/Users/ username /Library/Android/sdk/platform-tools/
导出 PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/
save file and reload file保存文件并重新加载文件
source ~/.bash_profile
源 ~/.bash_profile
check if adb was set into path检查 adb 是否设置为路径
adb version
亚行版
One liner version一排版
Echo your export command and redirect the output to be appended to .bash_profile file and restart terminal.回显您的导出命令并将输出重定向到 .bash_profile 文件并重新启动终端。 (have not verified this but should work)
(尚未验证这一点,但应该可以工作)
echo "export PATH=$PATH:/Users/ username /Library/Android/sdk/platform-tools/ sdk/platform-tools/" >> ~/.bash_profile
echo "export PATH=$PATH:/Users/ username /Library/Android/sdk/platform-tools/sdk/platform-tools/" >> ~/.bash_profile
Why are you trying to run "./adb"?你为什么要运行“./adb”? That skips the path variable entirely and only looks for "adb" in the current directory.
这完全跳过了路径变量,只在当前目录中查找“adb”。 Try running "adb" instead.
尝试运行“adb”。
Edit: your path looks wrong.编辑:您的路径看起来不对。 You say you get
你说你得到
/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
You're missing the /Users/simon part.您缺少 /Users/simon 部分。
Also note that if you have both .profile and .bash_profile files, only the latter gets executed.另请注意,如果您同时拥有 .profile 和 .bash_profile 文件,则只会执行后者。
On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.在我的 Macbook Pro 上,我已将导出行添加到 ~/.bash_profile,而不是 .profile。
eg例如
export PATH=/Users/me/android-sdk-mac_86/platform-tools:/Users/me/android-sdk-mac_86/tools:$PATH
Just encase anyone finds this SO post when using Android Studio which includes the SDK has part of the App package (on Mac OSX).在使用包含 SDK 的 Android Studio 时,任何人都会发现此 SO 帖子,其中包含应用程序包的一部分(在 Mac OSX 上)。
So as @davecaunt and @user1281750 noted but insert the following line to .bash_profile正如@davecaunt 和@user1281750 指出的那样,但将以下行插入到 .bash_profile
export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools:$PATH
The answer for MAC should be: MAC的答案应该是:
Open your bash_profile with the following commands: open ~/.bash_profile
使用以下命令打开您的 bash_profile:
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.如果基本配置文件不存在,请使用以下命令创建一个新文件:
touch .bash_profile
然后重复第 1 阶段。
Add the following line: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH
添加以下行:
export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH
Restart your bash window and test by typing adb shell
重新启动 bash 窗口并通过键入
adb shell
测试
Good luck!祝你好运! :-)
:-)
In your terminal, navigate to home directory在您的终端中,导航到主目录
cd
create file .bash_profile
touch .bash_profile
open file with TextEdit
open -e .bash_profile
insert line into TextEdit
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
save file and reload file
source ~/.bash_profile is very important check if adb was set into path source ~/.bash_profile检查 adb 是否设置为路径非常重要
adb version
It should be fine now.现在应该没问题了。
I use zsh and Android Studio.我使用 zsh 和 Android Studio。 I use a variable for my Android SDK path and configure in the file
~/.zshrc
:我使用一个变量作为我的 Android SDK 路径并在文件
~/.zshrc
配置:
export ANDROID_HOME=/Applications/Android\ Studio.app/sdk
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
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 installs the adb tool in this path: Android Studio v1.2安装adb工具在这个路径:
~/Library/Android/sdk/platform-tools/adb
So it goes like this:所以它是这样的:
adb version
and expect an error outputadb version
并期待错误输出touch ~/.bash_profile
open ~/.bash_profile
source ~/.bash_profile
adb version
and expect an outputadb version
并期待输出Good luck!祝你好运!
In order to make the terminal always have the file ~/.bashrc
and there put the path you wish to use, by adding:为了使终端始终拥有文件
~/.bashrc
并在其中放置您希望使用的路径,通过添加:
export PATH=$PATH:/XXX
where XXX is the path that you wish to use.其中 XXX 是您希望使用的路径。
for adb, here's what i use:对于 adb,这是我使用的:
export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/
(where "user" is my user name). (其中“用户”是我的用户名)。
It appears that you're still trying to execute adb
with ./adb
.看来您仍在尝试使用
./adb
执行adb
。 That asks the shell to run the program named adb
in the current working directory .这要求 shell在当前工作目录中运行名为
adb
的程序。
Try just adb
without ./
.试试没有
./
adb
。
I added export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/
into both places .bash_profile
and .profile
to make sure it works.我将
export PATH=${PATH}:/Users/mishrapranjal/android-sdks/platform-tools/
到两个地方.bash_profile
和.profile
以确保它工作。 Still it wasn't working and then I looked at sarnold's tip about restarting terminal and it worked like a charm.仍然无法正常工作,然后我查看了sarnold关于重新启动终端的提示,它就像一个魅力。 It saved my time of adding every time this into the
PATH
whenever I had to run adb
.每当我必须运行
adb
时,它都会节省我每次将其添加到PATH
时间。 Thank you guys.谢谢你们。
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.如果任何人似乎无法到达
.bash_profile
文件以获取任何新路径,并且该文件中有其他命令(如别名命令),则尝试将 PATH 语句移动到文件顶部。
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.
所以这就是我的 PATH 语句没有运行的原因。 Moving it to the top just let it run first.
将它移动到顶部,让它先运行。
If you are Catalina user follow this如果您是 Catalina 用户,请遵循此
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要保持 PATH 更改并防止在关闭终端应用程序后将其清除,您需要将变量保留在 Catalina 的 zshrc 文件中
touch .zshrc触摸.zshrc
Open it with the TextEditor使用文本编辑器打开它
open -e .zshrc打开 -e .zshrc
Insert the command below to add ADB as PATH variable (replace username with your own)插入下面的命令以将 ADB 添加为 PATH 变量(将用户名替换为您自己的)
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/导出 PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
Save the file and close the TextEditor app.保存文件并关闭 TextEditor 应用程序。 Back to the Terminal app, insert the following to source the file
返回终端应用程序,插入以下内容以获取文件
source .zshrc源.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 Android Debug Bridge version 1.0.41 Version 31.0.2-7242960 安装为/Users/username/Library/Android/sdk/platform-tools//adb
In bash profile just add -在 bash 配置文件中添加 -
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
导出 PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
and then in terminal run -然后在终端运行 -
adb version
亚行版
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.在将路径变量添加到
.bash_profile
之前,请检查您的默认 shell。
Because i was seting path variable in .bash_profile
file but my default shell was zsh
that's why i have to run source ~/.bash_profile
each time before using adb command.因为我在
.bash_profile
文件中设置路径变量,但我的默认 shell 是zsh
这就是为什么我必须在每次使用 adb 命令之前运行source ~/.bash_profile
。
So first check your default shell:所以首先检查你的默认 shell:
echo $SHELL
/bin/bash
then you should set path variable in .bash_profile
/bin/bash
那么你应该在.bash_profile
中设置路径变量/bin/zsh
then you should set path variable in .zshrc
.zshrc
是/bin/zsh
那么你应该在 .zshrc 中设置路径变量And here is my path variable:这是我的路径变量:
export ANDROID_SDK_ROOT="/Users/aliasjad/Library/Android/sdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.