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

12,005

Solution 1

sudo means you're switching to root, and that does not necessarily mean that your environment comes along. That could be dangerous.

At your risk, add the -E option to inherit the calling environment.

Solution 2

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.

You should setup adb for root too:

adb Environmental Variables

Open ~/.bashrc and add the following to the very bottom

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

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

from adb setup

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

Solution 3

Since you are running adb as root in the second example, adb would also have to be on root's path.

Solution 4

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.

Solution 5

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.

$ gedit ~/.bashrc

set the path as follows in the .bashrc

export PATH=${PATH}:~/adt-bundle/tools
export PATH=${PATH}:~/adt-bundle/platform-tools
Share:
12,005
Searene
Author by

Searene

A social nerd.

Updated on June 11, 2022

Comments

  • Searene
    Searene almost 2 years
    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

    Then I executed adb start-server:

    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    

    Then 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?

  • Searene
    Searene about 12 years
    thx, i have tested -E option, but also failed, sudo -E adb install temp.apk ==> sudo: adb: command not found, doesnt '-E` option work for 'sudo'?
  • lamplightdev
    lamplightdev about 12 years
    from man sudo: The -E (preserve environment) option will override the env_reset option in sudoers(5)). It is only available when either the matching command has the SETENV tag or the setenv option is set in sudoers(5).