尝试将 adb 添加到 PATH 变量 OSX

发布于 2024-10-29 18:09:14 字数 748 浏览 1 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(17

半衾梦 2024-11-05 18:09:14

每次登录时添加到 PATH

Total control version

在终端中,导航到主目录

光盘

创建文件 .bash_profile

触摸.bash_profile

使用 TextEdit

打开文件

打开-e .bash_profile

将行插入 TextEdit

导出
PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/

保存文件并重新加载文件

源~/.bash_profile

检查 adb 是否设置到路径中

adb版本


One liner version

回显您的导出命令并将输出重定向到附加到 .bash_profile 文件并重新启动终端。 (尚未验证这一点,但应该有效)

echo "export PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/
sdk/platform-tools/" >> ~/.bash_profile

Add to PATH for every login

Total control version:

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

check if adb was set into path

adb version


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)

echo "export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/
sdk/platform-tools/" >> ~/.bash_profile

心碎无痕… 2024-11-05 18:09:14

替代方案:以简单的方式安装 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

洒一地阳光 2024-11-05 18:09:14

你为什么要尝试运行“./adb”?这完全跳过路径变量,只在当前目录中查找“adb”。尝试运行“adb”。

编辑:你的路径看起来错误。你说你明白

/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

你错过了 /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

/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.

Also note that if you have both .profile and .bash_profile files, only the latter gets executed.

[浮城] 2024-11-05 18:09:14

在我的 Macbook Pro 上,我已将导出行添加到 ~/.bash_profile,而不是 .profile。

例如

export PATH=/Users/me/android-sdk-mac_86/platform-tools:/Users/me/android-sdk-mac_86/tools:$PATH

On my Macbook Pro, I've added the export lines to ~/.bash_profile, not .profile.

e.g.

export PATH=/Users/me/android-sdk-mac_86/platform-tools:/Users/me/android-sdk-mac_86/tools:$PATH
枫林﹌晚霞¤ 2024-11-05 18:09:14

只要有人在使用 Android Studio 时发现这篇 SO 帖子,其中包含的 SDK 是应用程序包的一部分(在 Mac OSX 上)。

正如 @davecaunt 和 @user1281750 所指出的,但将以下行插入 .bash_profile

export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-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).

So as @davecaunt and @user1281750 noted but insert the following line to .bash_profile

export PATH=/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools:$PATH
睡美人的小仙女 2024-11-05 18:09:14

MAC 的答案应该是:

  1. 使用以下命令打开您的 bash_profile:open ~/.bash_profile

  2. 如果基本配置文件不存在,请使用以下命令创建一个新文件:touch .bash_profile 然后重复第 1 阶段。 p>

  3. 添加以下行:export PATH= /Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH

  4. 重新启动您的 bash 窗口并通过输入 adb shell 进行测试

祝你好运! :-)

The answer for MAC should be:

  1. Open your bash_profile with the following commands: open ~/.bash_profile

  2. In case base profile file doesn't exist, create a new one with the following command: touch .bash_profile then repeat phase 1.

  3. Add the following line: export PATH=/Users/"YOURUSER"/Library/Android/sdk/platform-tools:$PATH

  4. Restart your bash window and test by typing adb shell

Good luck! :-)

情痴 2024-11-05 18:09:14

在终端中,导航到主目录

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 非常重要
检查 adb 是否设置为路径

adb version

现在应该没问题了。

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

adb version

It should be fine now.

江南月 2024-11-05 18:09:14

我使用 zsh 和 Android Studio。我对 Android SDK 路径使用变量,并在文件 ~/.zshrc 中进行配置:

export ANDROID_HOME=/Applications/Android\ Studio.app/sdk
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"

注意:确保指定路径周围不要包含单引号或双引号。如果这样做,它将不起作用。

I use zsh and Android Studio. I use a variable for my Android SDK path and configure in the file ~/.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.

澉约 2024-11-05 18:09:14

Android Studio v1.2 在这个路径中安装 adb 工具:

~/Library/Android/sdk/platform-tools/adb

所以它是这样的:

  1. 运行终端
  2. 运行 adb version 并期望错误输出
  3. touch ~/.bash_profile
  4. open ~/.bash_profile
  5. 在“关闭”之前添加上述路径:$PATH
  6. source ~/.bash_profile
  7. run adb version 并期望输出

祝你好运!

Android Studio v1.2 installs the adb tool in this path:

~/Library/Android/sdk/platform-tools/adb

So it goes like this:

  1. Run Terminal
  2. run adb version and expect an error output
  3. touch ~/.bash_profile
  4. open ~/.bash_profile
  5. add the above path before the 'closing' :$PATH
  6. source ~/.bash_profile
  7. run adb version and expect an output

Good luck!

半边脸i 2024-11-05 18:09:14

您似乎仍在尝试使用 ./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 named adb in the current working directory.

Try just adb without ./.

廻憶裏菂餘溫 2024-11-05 18:09:14

为了使终端始终具有文件 ~/.bashrc 并放置您希望使用的路径,请添加:

export PATH=$PATH:/XXX

其中 XXX 是您希望使用的路径。

对于 adb,这是我使用的:(

export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/

其中“user”是我的用户名)。

In order to make the terminal always have the file ~/.bashrc and there put the path you wish to use, by adding:

export PATH=$PATH:/XXX

where XXX is the path that you wish to use.

for adb, here's what i use:

export PATH=$PATH:/home/user/Android/android-sdk-linux_x86/platform-tools/

(where "user" is my user name).

神魇的王 2024-11-05 18:09:14

输入图片这里的描述

第二个解决方案解释如下。但是当我关闭终端时,我在路径变量中所做的更改就会丢失。因此我更喜欢第一种方式!

输入图片此处描述

enter image description here

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!

enter image description here

灼痛 2024-11-05 18:09:14

如果您是 Catalina 用户,请按照此

  1. 确保位于主目录中

    cd~

  2. 要保留 PATH 更改并防止其在关闭终端应用程序后被清理,您需要将变量保留在 Catalina 的 zshrc 文件中

    触摸.zshrc

  3. 的 zshrc 文件中

    使用文本编辑器打开它

    打开-e.zshrc

  4. 插入下面的命令将 ADB 添加为 PATH 变量(用您自己的用户名替换用户名)

    导出 PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/

  5. 保存文件并关闭 TextEditor 应用程序。返回终端应用程序,插入以下内容以获取文件

    源代码.zshrc

  6. 就完成了!我们来测试一下是否成功

    adb版本

  7. 您应该期待类似的内容

    Android 调试桥版本 1.0.41
    版本31.0.2-7242960
    安装为 /Users/用户名/Library/Android/sdk/platform-tools//adb

If you are Catalina user follow this

  1. Make sure to be in the Home directory

    cd ~

  2. 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

  3. Open it with the TextEditor

    open -e .zshrc

  4. 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/

  5. Save the file and close the TextEditor app. Back to the Terminal app, insert the following to source the file

    source .zshrc

  6. And you’re done! Let’s test if it was successful

    adb version

  7. 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

少钕鈤記 2024-11-05 18:09:14

我将 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 run adb.
Thank you guys.

于我来说 2024-11-05 18:09:14

如果任何人似乎无法到达 .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.

颜漓半夏 2024-11-05 18:09:14

在 bash 配置文件中
只需添加 -

导出 PATH=$PATH:/Users/用户名/Library/Android/sdk/platform-tools/

然后在终端运行 -

adb版本

In bash profile
just add -

export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools/

and then in terminal run -

adb version

独行侠 2024-11-05 18:09:14

所有答案都写得很好并且很有帮助,但我想提一件事。在将路径变量添加到 .bash_profile 之前,请检查您的默认 shell。

因为我在 .bash_profile 文件中设置路径变量,但我的默认 shell 是 zsh 这就是为什么我每次都必须运行 source ~/.bash_profile在使用 adb 命令之前。

因此,首先检查您的默认 shell:

echo $SHELL
  • 如果输出是 /bin/bash 那么您应该在中设置路径变量
    .bash_profile
  • 如果输出是 /bin/zsh 那么你应该在 .zshrc 中设置路径变量

,这是我的路径变量:

export ANDROID_SDK_ROOT="/Users/aliasjad/Library/Android/sdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"

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 was zsh that's why i have to run source ~/.bash_profile each time before using adb command.

So first check your default shell:

echo $SHELL
  • if the output is /bin/bash then you should set path variable in
    .bash_profile
  • If the output is /bin/zsh then you should set path variable in .zshrc

And here is my path variable:

export ANDROID_SDK_ROOT="/Users/aliasjad/Library/Android/sdk"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文