SATOHOST
No Result
View All Result
Thứ Tư, Tháng Năm 18, 2022
  • Login
  • vps giá rẻ
Subscribe
SATOHOST
  • vps giá rẻ
No Result
View All Result
SATOHOST
No Result
View All Result
Home Blog

Mac OS X: Set / Change $PATH Variable

admin by admin
Tháng Sáu 3, 2019
in Blog
5 min read
0
152
SHARES
1.9k
VIEWS
Share on FacebookShare on Twitter

I need to add dev tools (such as JDK and friends) to my PATH. How do I change $PATH variable in OS X 10.8.x? Where does $PATH get set in OS X 10.8 Mountain Lion?

$PATH is nothing but an environment variable on Linux, OS X, Unix-like operating systems, and Microsoft Windows. You can specify a set of directories where executable programs are located using $PATH. The $PATH variable is specified as a list of directory names separated by colon (:) characters. To print the current settings, open the Terminal and then type:

echo "$PATH"

echo "$PATH"

OR

printf "%sn" $PATH

printf "%sn" $PATH

Sample outputs:

Fig.01: Displaying the current $PATH settings using echo / printf on OS X

OS X: Change your PATH environment variable

You can add path to any one of the following method:

  1. $HOME/.bash_profile file using export syntax.
  2. /etc/paths.d directory.

Method #1: $HOME/.bash_profile file

The syntax is as follows:

export PATH=$PATH:/new/dir/location1
export PATH=$PATH:/new/dir1:/dir2:/dir/path/no3

export PATH=$PATH:/new/dir/location1
export PATH=$PATH:/new/dir1:/dir2:/dir/path/no3

In this example, add /usr/local/sbin/modemZapp/ directory to $PATH variable. Edit the file $HOME/.bash_profile, enter:
vi $HOME/.bash_profile
OR
vi ~/.bash_profile
Append the following export command:

export PATH=$PATH:/usr/local/sbin/modemZapp

export PATH=$PATH:/usr/local/sbin/modemZapp

Save and close the file. To apply changes immedialty enter:
source $HOME/.bash_profile
OR
. $HOME/.bash_profile
Finally, verify your new path settings, enter:
echo $PATH
Sample outputs:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/sbin/modemZapp

Method #2: /etc/paths.d directory

Apple recommends the path_helper tool to generate the PATH variable i.e. helper for constructing PATH environment variable. From the man page:

The path_helper utility reads the contents of the files in the directories /etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and MANPATH environment variables respectively.

(The MANPATH environment variable will not be modified unless it is already set in the environment.)

Files in these directories should contain one path element per line.

Prior to reading these directories, default PATH and MANPATH values are obtained from the files /etc/paths and /etc/manpaths respectively.

To list existing path, enter:
ls -l /etc/paths.d/
Sample outputs:

total 16
-rw-r--r--  1 root  wheel  13 Sep 28  2012 40-XQuartz

You can use the cat command to see path settings in 40-XQuartz:
cat /etc/paths.d/40-XQuartz
Sample outputs:

/opt/X11/bin

To set /usr/local/sbin/modemZapp to $PATH, enter:

sudo -s 'echo "/usr/local/sbin/modemZapp" > /etc/paths.d/zmodemapp'

sudo -s ‘echo "/usr/local/sbin/modemZapp" > /etc/paths.d/zmodemapp’

OR use vi text editor as follows to create /etc/paths.d/zmodemapp file:
sudo vi /etc/paths.d/zmodemapp
and append the following text:

/usr/local/sbin/modemZapp

Save and close the file. You need to reboot the system. Alternatively, you can close and reopen the Terminal app to see new $PATH changes.

Conclusion

  1. Use $HOME/.bash_profile file when you need to generate the PATH variable for a single user account.
  2. Use /etc/paths.d/ directory via the path_helper tool to generate the PATH variable for all user accounts on the system. This method only works on OS X Leopard and higher.
See also:
  • Customize the bash shell environments from the Linux shell scripting wiki.
  • UNIX: Set Environment Variable
  • Man pages – bash(1), path_helper(8)
Share on Facebook Twitter

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

0
Tags: blog
admin

admin

Related Posts

edit post
Blog

LINUX BACKUP & RESTORE FULL OS

Tháng Ba 23, 2022
edit post
Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z
Blog

VPS Ram 4GB Chỉ 199k/tháng Miễn Phí Gsuite,

Tháng Ba 23, 2022
edit post
Blog

Tài Khoản Google Drive Unlimited 2020 50k – Google Drive Không Giới Hạn – Google drive unlimited 2020

Tháng Bảy 11, 2020
edit post
Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)
Blog

Bán tài khoản MOVO CASH USA ACCOUNT (VCC+VBA)

Tháng Bảy 11, 2020
edit post
Blog

Hướng dẫn kích hoạt bản quyền Windows Server 2012 R2 không cần crack

Tháng Sáu 10, 2020
edit post
Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z
Blog

Hướng dẫn cài đặt và cấu hình Openstack toàn tập từ A-Z

Tháng Sáu 4, 2020
edit post
Hướng dẫn Tự Tạo Ứng Dụng Họp Online Phòng Học Online Miễn Phí với Jitsi
Blog

Hướng dẫn Tự Tạo Ứng Dụng Họp Online Phòng Học Online Miễn Phí với Jitsi

Tháng Tư 13, 2020
edit post
Hướng dẫn sử dụng Remote Desktop để truy cập VPS
Blog

Hướng dẫn sử dụng Remote Desktop để truy cập VPS

Tháng Tư 12, 2020
edit post
Download Kali Linux 2020.1
Blog

Download Kali Linux 2020.1

Tháng Tư 12, 2020
vps giá rẻ
  • vps giá rẻ
Call us: 0975757375

© 2020

No Result
View All Result
  • vps giá rẻ

© 2020

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
  • Sign in

Forgot your password?

Lost your password? Please enter your email address. You will receive mail with link to set new password.

Back to login