I'm trying to add /data/bin to variable PATH at startup in order to have it available for any other app.
In Ubuntu I use the file /etc/environment, I cannot find anything similar in Android.
I discovered that adb shell detects /data/bin existence and adds it to PATH, the system doesn't seem to do the same at boot though.

2 Answers 2


I discovered that adb shell detects /data/bin existence and adds it to PATH, the system doesn't seem to do the same at boot though.

It's because adb shell starts a shell process (Android's default is MirBSD Korn Shell) which reads its configuration file /etc/mkshrc and can easily change environment variables. But apps inherit their environment from zygote, so we need to set variables before zygote starts.

Edit /init.rc file or any other .rc file or create your own. Append or prepend directories to Android's default PATH:

# /system/etc/init/path.rc

on init
    export PATH /data/bin:/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin


On Linux distros /etc/environment is evaluated by PAM (a set of libraries called modules) which is a centralized authentication mechanism used by privilege granting and administering programs like login, su, sshd, passwd, useradd etc. First process init - after starting system services - drops us to a login shell or display manager (which starts a display server like X.Org to show GUI), running on a virtual terminal. When logging in a user, shells and display managers are configured to read and set environment from different files like passwd, login.defs, profile, bashrc xsessionrc etc. usually found in /etc or user's HOME directory. This environment is inherited by CLI utilities as well as GUI programs which run in desktop environment, including terminal emulators. Applications which attach to terminals also set TERM.

However on Android there is no concept of getty, login, text terminal logins and traditional X window system. There are no user sessions and hence no login files. init starts zygote which loads Android's Java framework, and after starting services in system_server, it forks virtual machines in which apps run. So the first thing we see (after animation ends) is an app; System UI (lock screen) or Home/Launcher app hosted by SurfaceFlinger - Android's display server. Mainly environment of all these programs is set in init's .rc files through export command. /init.environ.rc (1) exports variables like ANDROID_ROOT, ANDROID_DATA, ANDROID_STORAGE and others. Or programs set some variables themselves e.g. logd sets TZ (2) to ensure correct timestamps in logcat, and adbd sets EXTERNAL_STORAGE (3).

Commonly used variables for Java framework are defined here. PATH is set by init on boot (4) and is part of Bionic libc definitions (5). CLI shell utilities like su (6) and run-as (7) also define PATH, HOME, LOGNAME, USER, SHELL etc. DOWNLOAD_CACHE is set in /init.rc (8) and ANDROID_ROOT is set by zygote (9) itself.

Shell specific configuration files like bashrc or mkshrc are read only if you use adb shell or a terminal emulator app.



Edit the file: /system/etc/bash/bashrc and export your environment variable there..

Actually, the default environment variables are predefined in the ramdisk's file: init.environ.rc. (You may unpack the boot.img to edit it and repack & flash it)..

You may also modify those system variables in the bashrc file itself..

Also check the /system/etc/mkshrc file..

  • 1
    I appended export PATH="$PATH:/data/bin" to /system/etc/bash/bashrc, reboot, no success. In /init.environ.rc, no sign for variable PATH and search for any bin goes blank, not that I'm so keen for editing boot.img. Could you please give some practical example?
    – Claudio
    Sep 20, 2016 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .