Linux how to add folder to path

Содержание
  1. Как добавить каталог в PATH в Linux
  2. How to Add a Directory to PATH in Linux
  3. В этой статье показано, как добавить каталоги в ваши $PATH системы Linux.
  4. Что есть $PATH в Linux
  5. Добавление каталога в ваш $PATH
  6. Вывод
  7. Как добавить каталог в PATH в Linux
  8. Что такое $PATH в Linux
  9. Добавление каталога в ваш $PATH
  10. Выводы
  11. How to add directory to system path in Linux
  12. Setting PATH for your current shell session
  13. Using export to pass the PATH environment variable to child processes
  14. Setting the PATH variable for every new shell session
  15. Add Folder To Path Linux Search
  16. How to add a directory to $PATH on Linux — …
  17. Search
  18. How to Add a Directory to PATH in Linux Linuxize
  19. Search
  20. Add directory to path in Linux – William’s blog
  21. Search
  22. Adding any current directory ‘./’ to the search path in …
  23. Search
  24. How to add directory to system path in Linux
  25. Search
  26. How to Add Directory to $PATH Variable in Linux
  27. Search
  28. How to find a folder in Linux using the command line
  29. Search
  30. How can I set all subdirectories of a directory into …
  31. Search
  32. Linux 101: How to add directories to your Linux $PATH
  33. Search
  34. environment variables — How to add a directory to the …
  35. Search
  36. How to Add a Directory to PATH on CentOS 8
  37. Search
  38. How to Add Directory to PATH in Linux — TecNStuff
  39. Search
  40. Adding a Path to the Linux PATH Variable Baeldung …
  41. Search
  42. configuration — Adding a directory to $PATH in CentOS
  43. Search
  44. How to add directories to your $PATH in Linux — …
  45. Search
  46. [SOLVED] Add folder to $PATH — Linux Mint Forums
  47. Search
  48. Add folders to search path — MATLAB addpath
  49. Search
  50. Add a directory to PATH in ZSH — Koen Woortman
  51. Search
  52. command line — Adding a directory to the PATH …
  53. Search
  54. Understanding file paths and how to use them in Linux
  55. Search
  56. Find Files and Directories on Linux Easily – devconnected
  57. Search
  58. TCSH / CSH Shell Set PATH Variable — nixCraft
  59. Search
  60. How to add shared libraries to Linux’s system library path
  61. Search
  62. Find Path of a Command with whereis — Linux Hint
  63. Search
  64. environment variables — Add bash script folder to path
  65. Search
  66. shell — adding programs to path — Unix & Linux Stack …
  67. Search
  68. How to set your $PATH variable in Linux …
  69. Search
  70. How to find path of any folder or file using locate and
  71. Search
  72. Setting your search path — Linux Migration
  73. Search
  74. How to Set the $PATH Variable in Linux — MUO
  75. Search
  76. How do I add /usr/local/bin to path — Arch Linux …
  77. Search
  78. Add A Directory To A PATH Environment Variable On …
  79. Search
  80. Linux — Library Path (LD_LIBRARY_PATH, LIBPATH, …
  81. Search
  82. How to set the PATH variable in Linux — Putorius
  83. Search
  84. Add Folders to the MATLAB Search Path at Startup — …
  85. Search
  86. Linux path environment variable — Linux Tutorials — …
  87. Search
  88. How To Find a File In Linux From the Command Line — …
  89. Search
  90. How to Access Windows Shared Folder from Linux — …
  91. Search
  92. Search

Как добавить каталог в PATH в Linux

How to Add a Directory to PATH in Linux

В этой статье показано, как добавить каталоги в ваши $PATH системы Linux.

Когда вы вводите команду в командной строке, вы в основном говорите оболочке запустить исполняемый файл с заданным именем. В Linux эти исполняемые программы , такие как ls , find , file и другие, как правило , живут внутри несколько различных каталогов в вашей системе. Любой файл с разрешением на выполнение, хранящийся в этих каталогах, может быть запущен из любого места. Наиболее распространенные каталоги , которые содержат исполняемые программы /bin , /sbin , /usr/sbin , /usr/local/bin и /usr/local/sbin .

Но как оболочка узнает, в каких каталогах искать исполняемые программы или оболочка выполняет поиск по всей файловой системе?

Ответ прост. Когда вы вводите команду, оболочка ищет во всех каталогах, указанных в пользовательской $PATH переменной, исполняемый файл с таким именем.

Что есть $PATH в Linux

$PATH Переменная окружающей среды является двоеточиями список каталогов, сообщает оболочке , какие каталоги для поиска исполняемых файлов.

Чтобы проверить, какие каталоги у вас есть $PATH , вы можете использовать команду printenv или echo :

Вывод будет выглядеть примерно так:

Если у вас есть два исполняемых файла с одинаковым именем, расположенные в двух разных каталогах, оболочка запустит файл, который находится в каталоге, который стоит первым в $PATH .

Добавление каталога в ваш $PATH

Есть ситуации, когда вы можете захотеть добавить другие каталоги в $PATH переменную. Например, некоторые программы могут быть установлены в разных местах, или вы можете захотеть иметь выделенный каталог для ваших личных записей, но сможете запускать их без указания абсолютного пути к исполняемым файлам. Для этого вам просто нужно добавить каталог в свой $PATH .

Читайте также:  Windows message ctrl c

Допустим, у вас есть каталог с именем, bin расположенный в вашем домашнем каталоге, в котором вы храните свои сценарии оболочки. Чтобы добавить каталог к ​​вашему $PATH типу в:

Команда export экспортирует измененную переменную в дочерние среды процессов оболочки.

Теперь вы можете запускать свои скрипты, просто набрав имя исполняемого скрипта без указания полного пути к исполняемому файлу.

Однако это изменение носит временный характер и действует только в текущем сеансе оболочки.

Чтобы сделать изменение постоянным, вам нужно определить $PATH переменную в файлах конфигурации оболочки. В большинстве дистрибутивов Linux при запуске нового сеанса переменные среды считываются из следующих файлов:

Конфигурационные файлы глобальной оболочки, такие как /etc/environment и /etc/profile . Используйте этот файл, если вы хотите, чтобы новый каталог был добавлен всем системным пользователям $PATH .

Конфигурационные файлы для отдельных пользовательских оболочек. Например, если вы используете Bash, вы можете установить $PATH переменную в

/.bashrc файле, а если вы используете Zsh — имя файла

В этом примере мы установим переменную в

/.bashrc файле. Откройте файл в текстовом редакторе и добавьте в конце следующую строку:

Чтобы подтвердить, что каталог был успешно добавлен, напечатайте его значение $PATH , набрав:

Вывод

Добавить новые каталоги в вашу пользовательскую или глобальную $PATH переменную довольно просто. Это позволяет выполнять команды и сценарии, хранящиеся в нестандартных местах, без необходимости вводить полный путь к исполняемому файлу.

Те же инструкции применимы для любого дистрибутива Linux, включая Ubuntu, CentOS, RHEL, Debian и Linux Mint.

Источник

Как добавить каталог в PATH в Linux

Когда вы вводите команду в командной строке, вы в основном говорите оболочке запустить исполняемый файл с заданным именем. В Linux эти исполняемые программы, такие как ls , find , file и другие, обычно find в нескольких разных каталогах вашей системы. Любой файл с исполняемыми разрешениями, хранящийся в этих каталогах, может быть запущен из любого места. Наиболее распространенные каталоги, содержащие исполняемые программы, — это /bin , /sbin , /usr/sbin , /usr/local/bin и /usr/local/sbin .

Но как оболочка узнает, в каких каталогах искать исполняемые программы? Оболочка выполняет поиск по всей файловой системе?

Ответ прост. Когда вы вводите команду, оболочка просматривает все каталоги, указанные в $PATH пользователя, в поисках исполняемого файла с таким именем.

В этой статье показано, как добавить каталоги в $PATH в системах Linux.

Что такое $PATH в Linux

Переменная среды $PATH представляет собой список каталогов, разделенных двоеточиями, который сообщает оболочке, в каких каталогах следует искать исполняемые файлы.

Чтобы проверить, какие каталоги находятся в вашем $PATH , вы можете использовать команду printenv или echo :

Результат будет выглядеть примерно так:

Если у вас есть два исполняемых файла с одинаковым именем, расположенных в двух разных каталогах, оболочка запустит файл, который находится в каталоге, который идет первым в $PATH .

Добавление каталога в ваш $PATH

Бывают ситуации, когда вы можете захотеть добавить другие каталоги в $PATH . Например, некоторые программы могут быть установлены в разных местах или вы можете захотеть иметь специальный каталог для ваших личных сценариев, но иметь возможность запускать их, не указывая абсолютный путь к исполняемым файлам. Для этого вам просто нужно добавить каталог в ваш $PATH .

Допустим, у вас есть каталог bin расположенный в вашем домашнем каталоге, в котором вы храните сценарии оболочки. Чтобы добавить каталог в ваш $PATH введите:

Команда export экспортирует измененную переменную в среду дочернего процесса оболочки.

Теперь вы можете запускать свои сценарии, вводя имя исполняемого сценария без необходимости указывать полный путь к файлу.

Однако это изменение носит временный характер и действует только в текущем сеансе оболочки.

Чтобы сделать изменение постоянным, вам необходимо определить $PATH в файлах конфигурации оболочки. В большинстве дистрибутивов Linux при запуске нового сеанса переменные среды считываются из следующих файлов:

Глобальные файлы конфигурации оболочки, такие как /etc/environment и /etc/profile . Используйте этот файл, если хотите, чтобы новый каталог был добавлен всем пользователям системы $PATH .

Файлы конфигурации для конкретной оболочки пользователя. Например, если вы используете Bash, вы можете установить $PATH в файле

/.bashrc . Если вы используете Zsh, имя файла

В этом примере мы установим переменную в файле

/.bashrc . Откройте файл в текстовом редакторе и добавьте в конец следующую строку:

Сохраните файл и загрузите новый $PATH в текущий сеанс оболочки с помощью source команды:

Чтобы убедиться, что каталог был успешно добавлен, распечатайте значение вашего $PATH , набрав:

Читайте также:  Как установить fatrat kali linux

Выводы

Добавить новые каталоги к вашему пользователю или глобальной $PATH довольно просто. Это позволяет выполнять команды и сценарии, хранящиеся в нестандартных местах, без необходимости вводить полный путь к исполняемому файлу.

Те же инструкции применимы для любого дистрибутива Linux, включая Ubuntu, CentOS, RHEL, Debian и Linux Mint.

Не стесняйтесь оставлять комментарии, если у вас есть вопросы.

Источник

How to add directory to system path in Linux

In Linux, the PATH environment variable stores the names of paths that will be searched for the executable files of any commands typed in the command line. The value of the PATH environment variable is a string containing a series of pathnames, each delimited by a colon. For instance, the default PATH on a typical system might look like this:

When you type a command such as cat and press Enter , the shell searches each of these directories for an executable file named cat. The first one it finds is the one it runs.

To view the current value of your PATH environment variable, you can use the echo command. As with all variables in the shell, when referring to the value you need to put a dollar sign before the variable name:

In the above example, the current value of path return you to the command prompt.

Setting PATH for your current shell session

You can set the value of PATH as you would any other shell variable, with the form NAME=VALUE, like this:

The problem with this command is that it will completely overwrite the values you had before, which you probably don’t want. If you want to add a new value in addition to the old ones. You can accomplish this by referring to PATH in the new definition, like this:

Using the command above adds your new path to the current value of PATH. Since the pathnames are searched in order, you probably want to add your new path at the end of the variable as we’ve done here. Instead, if you typed:

Your new path would be searched before, not after, the default system paths.

Using export to pass the PATH environment variable to child processes

This type of PATH definition sets the environment variable for your current shell session, but any new programs you run might not see the new path you’ve added. That’s because your shell lets you control the environment by requiring you to manually declare what environment variables are passed on to other programs and processes. You can accomplished this with the export command. If you run:

Any processes you run until you log out use the current value of PATH.

If you prefer, you can combine these two commands into a single line, for convenience. Put a semicolon between them so that the shell knows they’re separate commands:

If any of your pathnames have spaces in them, enclose the variable definition in quotation marks, to be safe.

Setting the PATH variable for every new shell session

The methods we’ve used so far only sets the environment variable for your current shell session; when you logout or close the terminal window, your changes will be forgotten. If you want to set PATH to a certain value every time you log in or start a new shell session, add it to your bash startup script. Every time you start an interactive shell session, bash reads the following files in order (if they exist), and executes the commands inside of them:

The first file, /etc/profile, is the default startup script for every user on the system. One or more of the remaining three files are located in the home directory of every user. Any of those three can be used, but it’s important to know that they will be searched for in this order.

You can edit these files and manually change any lines containing PATH= definitions. Be careful if you do so, because these are the directories used to locate important operating system files.

If you want to add a path for your current user only, you can leave the other PATH= lines untouched. Add a line like this to the end of the file:

If you add this to the end of the .bash_profile file in your home directory, it takes effect every time your user starts a new shell session. If you add this to /etc/profile, it takes effect for every user on the system. Note that you need administrator privileges if you want to edit /etc/profile, so you can use sudo (or be logged in as root) to do so.

Читайте также:  Как посмотреть процесс загрузки windows 10

Источник

How to add a directory to $PATH on Linux — …

› Verified 2 days ago

How to Add a Directory to PATH in Linux Linuxize

Search

› Verified 4 days ago

Add directory to path in Linux – William’s blog

Search

› Verified 8 days ago

Search

› Verified 1 days ago

How to add directory to system path in Linux

Search

› Verified 8 days ago

How to Add Directory to $PATH Variable in Linux

Search

› Verified 3 days ago

How to find a folder in Linux using the command line

Search

› Verified 3 days ago

How can I set all subdirectories of a directory into …

Search

/scripts), so their security is the same. – MestreLion Dec 31 ’15 at 12:14

› Verified 4 days ago

Linux 101: How to add directories to your Linux $PATH

Search

› Verified 9 days ago

environment variables — How to add a directory to the …

Search

› Verified 2 days ago

How to Add a Directory to PATH on CentOS 8

Search

› Verified 8 days ago

How to Add Directory to PATH in Linux — TecNStuff

Search

› Verified Just Now

Adding a Path to the Linux PATH Variable Baeldung …

Search

› Verified 4 days ago

configuration — Adding a directory to $PATH in CentOS

Search

› Verified 7 days ago

How to add directories to your $PATH in Linux — …

Search

› Verified 2 days ago

[SOLVED] Add folder to $PATH — Linux Mint Forums

Search

› Verified 9 days ago

Add folders to search path — MATLAB addpath

Search

› Verified 4 days ago

Add a directory to PATH in ZSH — Koen Woortman

Search

› Verified 1 days ago

command line — Adding a directory to the PATH …

Search

› Verified 6 days ago

Understanding file paths and how to use them in Linux

Search

› Verified 6 days ago

Find Files and Directories on Linux Easily – devconnected

Search

As a reminder, here is how file permissions work on Linux. To find all files that have full permissions (a 777 given the binary notation), you can run the following command

› Verified 8 days ago

TCSH / CSH Shell Set PATH Variable — nixCraft

Search

› Verified Just Now

How to add shared libraries to Linux’s system library path

Search

› Verified 1 days ago

Find Path of a Command with whereis — Linux Hint

Search

› Verified 8 days ago

environment variables — Add bash script folder to path

Search

› Verified 8 days ago

shell — adding programs to path — Unix & Linux Stack …

Search

› Verified 1 days ago

How to set your $PATH variable in Linux …

Search

› Verified Just Now

How to find path of any folder or file using locate and

Search

› Verified 3 days ago

Setting your search path — Linux Migration

Search

› Verified 3 days ago

How to Set the $PATH Variable in Linux — MUO

Search

› Verified 3 days ago

How do I add /usr/local/bin to path — Arch Linux …

Search

› Verified 8 days ago

Add A Directory To A PATH Environment Variable On …

Search

› Verified 7 days ago

Linux — Library Path (LD_LIBRARY_PATH, LIBPATH, …

Search

› Verified 8 days ago

How to set the PATH variable in Linux — Putorius

Search

/.bash_profile file. This file is read every time you login, so the PATH variable will be set and ready. NOTE: The tilde (

) is a special function meaning your home directory.

› Verified 3 days ago

Add Folders to the MATLAB Search Path at Startup — …

Search

› Verified 8 days ago

Linux path environment variable — Linux Tutorials — …

Search

› Verified 5 days ago

How To Find a File In Linux From the Command Line — …

Search

› Verified 2 days ago

How to Access Windows Shared Folder from Linux — …

Search

› Verified 9 days ago

/.local/share/fonts to search path for linux · Issue

Search

/.local/share/fonts/, which according to the arch linux wiki is the recommended path for user fonts:. To install fonts system-wide (available for all users), move the folder to the /usr/share/fonts/ directory. . The files need to be readable by

Источник

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