Linux path default value

What are the Default $PATH Values?

But in a minimal chroot environment created by debootstrap , $PATH only contains:

# echo $PATH /usr/sbin:/usr/bin:/sbin:/bin 

Environment path values are stored in .bashrc file in ubuntu.

The system-wide PATH variable is defined in /etc/environment

Thanks — I couldn’t find where this file was actually sourced, but it appears to be included by PAM, in e.g. /etc/pam.d/login (and cron, su, etc)

bash will set PATH to a hard-coded default value if it’s not set in the environment:

$ env -i bash -c 'echo $PATH' /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:. 

We can check that this value is indeed hard-coded, and not read from the environment or some file, using the strings utility:

$ strings /bin/bash | grep /usr/sbin /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:. 

However, I get a different result on my Arch Linux machine:

$ env -i bash -c 'echo $PATH' /usr/local/sbin:/usr/local/bin:/usr/bin 

So, the default is chosen at the time the bash binary was built, which depends on the Linux distribution in use.

PATH

The search path for commands. It is a colon-separated list of directories in which the shell looks for commands (see COMMAND EXECUTION below). A zero-length (null) directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon. The default path is system-dependent, and is set by the administrator who installs bash. A common value is /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin .

Here, «installs» likely refers to make install (as opposed to installing a pre-built binary using a package manager), so «administrator» would refer to the distribution vendor.

The «INVOCATION» section in the man page describes the startup process, which may affect the initial value of the variable.

Источник

What is the default value of LD_LIBRARY_PATH? [duplicate]

In my case, it seems as if LD_LIBRARY_PATH is set to the empty string. But all standard system tools still work fine, so I guess the dynamic linker checks for that case and uses some default for LD_LIBRARY_PATH in that case. What is that default value? I guess it at least includes /usr/lib but what else? Is there any good systematic way in figuring out the standard locations where the dynamic linker would search? This question is slightly different from what paths the dynamic linker will search in. Having a default value means, that it will use the value of LD_LIBRARY_PATH if given, or if not given, it will use the default value — which means, it will not use the default value if LD_LIBRARY_PATH is provided.

Читайте также:  Oracle linux rdp client

1 Answer 1

The usual dynamic linker on Linux uses a cache to find its libraries. The cache is stored in /etc/ld.so.cache , and is updated by ldconfig which looks on the paths it’s given in /etc/ld.so.conf (and nowadays typically files in /etc/ld.so.conf.d ). Its contents can be listed by running ldconfig -p .

So there is no default value for LD_LIBRARY_PATH , default library lookup doesn’t need it at all. If LD_LIBRARY_PATH is defined, then it is used first, but doesn’t disable the other lookups (which also include a few default directories).

  • Using the directories specified in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated.
  • Using the environment variable LD_LIBRARY_PATH , unless the executable is being run in secure-execution mode (see below), in which case it is ignored.
  • Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present.
  • From the cache file /etc/ld.so.cache , which contains a compiled list of candidate shared objects previously found in the augmented library path. If, however, the binary was linked with the -z nodeflib linker option, shared objects in the default paths are skipped. Shared objects installed in hardware capability directories (see below) are preferred to other shared objects.
  • In the default path /lib , and then /usr/lib . (On some 64-bit architectures, the default paths for 64-bit shared objects are /lib64 , and then /usr/lib64 .) If the binary was linked with the -z nodeflib linker option, this step is skipped.

If LD_LIBRARY_PATH is not set or is empty, it is ignored. If it is set to empty values (with LD_LIBRARY_PATH=: for example), those empty values are interpreted as the current directory.

Читайте также:  Linux headers amd64 ubuntu

Источник

Default values of PATH variable

After searching all over the internet, I came know where to alter the values of PATH variable in case of interactive/non-interactive — login/non-login shell combinations. Found from another post https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/ I have «/bin/sh» as default login shell and only /etc/profile file is being used to export all needed environment variables in my system. And in case of non-interactive login shell, /etc/profile is not being referred too, even though above link says it would. But still when I execute,

ssh -4 -q -o StrictHostKeyChecking=no root@xxxx "env" Password: SHELL=/bin/sh . **PATH=/usr/bin:/bin:/usr/sbin:/sbin** . 

I could see some default values for PATH variable. I would like to know where exactly these default values of PATH are being set.

2 Answers 2

You should not care at all where PATH is set. You should set PATH always in your shell startup file ( .profile or .bashrc ).

This way you do not rely on someone else’s soon useless assumption what directories should be in your PATH . The only one who knows is YOU.

and then add to your liking with

PATH=$PATH:$HOME/bin PATH=$PATH:/usr/local/bin PATH=$PATH:

PS: In your specific case, it looks like the PATH is inherited from the remote end’s SSH daemon which eventually forks your shell. If a shell does not inherit a PATH from its parent, it will set a default value that you can query with env -i /bin/sh -c ‘echo $PATH’ .

Источник

Ubuntu: Reset $PATH to factory default

Consequently, my $PATH variable now contains only my own directory, which is of course a problem. I don’t know exactly what was in the path before, but if I can reset to factory default I can start from there and add things as I need them. Is there an easy way to accomplish this?

Читайте также:  Spss statistics for linux

4 Answers 4

If you can, just log out and relog in.

Otherwise, you can start with

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 

This only works assuming that the contents you describe are in fact the default PATH value for the OP’s login shell; this might not be the case depending on his/her setup (especially if the OP is not the admin on the system and is using, for example, a login shell on an ISP-provided terminal account).

@Matt, I trimmed /usr/games out of my path and cut one item too many. /bin is the fallback folder in tha path. Thx. I’ve corrected. @Viktor, Agreed, I actually assumed a standard Ubuntu 10.10 installation from the tag and the level of difficulty of the question.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the —login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

So, on your system, it’s most likely that you just need to look at what the default PATH value is in /etc/profile, set that, and then build up based on what your own login/profile bash scripts do to PATH.

If you’re not using bash(1) but some other shell, then use «man thatShellName» to find out what it’s invocation behaviour is, and perform similar steps.

As a quick short-cut, in your current shell, (again, assuming you’re using bash(1)), type «bash —login» to get a new, login shell process; then, save the value of path with

then «exit» out of the login shell and type

export PATH=`cat /tmp/myPath.txt` 

(note the use of back-ticks in that last expression).

Or if you’re a terminal app that has copy/paste abilities, you can just «bash —login», and copy the PATH value to the clipboard, exit, and then «export PATH» and paste in the PATH value.

Источник

Оцените статью
Adblock
detector