HOW TO USE ADB AND FASTBOOT COMMANDS ON ANY DIRECTORY OF YOUR PC?

Adding adb and Fastboot to the Windows PATH (Method 1)

This isn’t really adding it to the Windows PATH variable per se, but more adding it to a folder that is already in the PATH variable. Simply copy your adb.exe, fastboot.exe, AdbWinApi.dll and AdbWinUsbApi.dll to C:\Windows and you’re good to go. You should be able to run adb and fastboot from the command line now. This is by far the easiest, most fool proof method for setting this up. If for whatever reason it doesn’t work, follow method 2.

Adding adb and Fastboot to the Windows PATH (Method 2)

Step 1

Open Windows Explorer and right click “My PC”. Select “Properties” and you will be greeted with a screen showing some system information.

Step 2

Select “Advanced System Settings”.

Step 3

Select “Environment Variables”

Step 4

Look for the variable named “Path” and double click it.

Step 5

Click “Browse” and navigate to the folder where you extracted your adb files. Next “okay” out of all of the Windows you have open. Start a new PowerShell or command prompt and type “adb” to verify the location has been added. If not, reboot your PC and try again.
Please ensure before you click “Browse” that no field is highlighted. If a field is highlighted you will end up replacing it. Click somewhere in the list that doesn’t contain an entry to ensure that you do not replace a field.


Adding adb and Fastboot to the Linux PATH

I will be using Ubuntu for this tutorial, via command line only. You can edit the .bashrc file via the GUI, but you will need to navigate to the root of your home directory and press Ctrl+H. Make sure you have the platform-tools downloaded and extracted.

Step 1

Note the path of the adb tools you extracted. For me, I extracted them to /home/adam/adb/platform-tools.

Step 2

You’ll need to edit your .bashrc file. Go back to your home directory and run the following command.
sudo nano .bashrc
If you prefer to use vi or gedit you can instead.

Step 3

Add the following line to the end of the .bashrc file. Be careful editing this file, do not add anything else or change anything else.


export PATH=${PATH}:/home/YOUR-USERNAME/path/to/adb
 
 
And type

adb
 
to check if it works. If it gives you an error (usually on 64-bit computers), install the packages glibc.i686 and libstdc++ and it should work.

READY TO GO...

SOURCE: XDA DEVELOPERS