PATH
환경 변수에 값을 셋팅하는 두 가지 방법 알아보기PATH
환경 변수가 셋팅되는 과정을 알아보자 (zsh 기준)/etc/paths
파일 수정하기
두 가지 방법
실행시킨 shell(bash, zsh)에 따라서 실행되는 ~/.bashrc
, ~/.zshrc
을 수정한다.
덮어쓰기 방식으로 추가한다.
# ~/.zshrc
export PATH=/Users/yunslee/Library/Python/3.8/bin:$PATH
shell이 켜지면, zprofile
이 실행된다.
zprofile
의 쉘 스크립트 코드는 아래와 같다.
Example : /etc/zprofile
# System-wide profile for interactive zsh(1) login shells.
# Setup user specific overrides for this in ~/.zprofile. See zshbuiltins(1)
# and zshoptions(1) for more details.
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
/usr/libexec/path_helper
가 호출된다.
/usr/libexec/path_helper
bin 파일이다.
man page를 읽어보자.
man path_helper
/etc/paths
, /etc/paths.d
를 이용하여 환경변수 PATH를 설정해준다고 설명하고 잇다.
터미널에 eval
/usr/libexec/path_helper -s`` 로 실행시켜보면, 다음과 같은 결과 가 나온다.
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/yunslee/Library/Python/3.8/bin"; export PATH;
/usr/libexec/path_helper
에서 export 하여 PATH를 셋팅한다.
Shell script가 내가 작성한 파일을 읽고, export로 PATH의 환경변수를 셋팅해준다.