Install
lastmod 2025-12-17created 2022-09-283 edits
The install command is a utility that copies files while setting permissions, owner, and group at the same time. It is more powerful than simply copying files with the cp command, and is mainly used in software installation scripts (Makefiles, etc.).
Options
-
-m,--mode=MODE: set file permissions (e.g. 755, 644) -
-o,--owner=OWNER: set owner -
-g,--group=GROUP: set group -
-d,--directory: create directories -
-D: automatically create all required parent directories -
-v,--verbose: verbose output -
-b,--backup: create backups -
-C,--compare: copy only when files differ -
-s,--strip: strip the symbol table from executables (reduces size)
cp vs install
- software installation - How is install different from cp? - Unix & Linux Stack Exchange
- software installation - Why use install rather than cp and mkdir? - Unix & Linux Stack Exchange
Reasons to use the install command instead of the cp command:
- install is mostly similar to cp but provides additionally the option to set the destination file properties directly without having to use chmod separately.
- The install command is normally used in installation scripts that come with packages and source code for installing a binary to your system. It can also be used to install any other file or directory. In addition to the -d and -c options you have -m for specifying the new permissions of the file to be installed, so you don't have to do a cp and a chmod to get the same result. For instance:
install -m644 "$srcdir/$pkgname-$pkgver-linux64" "$pkgdir/opt/$pkgname" - You also have options -g and -o for setting the target group and owner, respectively. This avoids separate calls to chown. In general, using install shortens your script and makes it more concise by doing file creation, copying, mode setting and related stuff in one command instead of many.
-
installcopies/installs files with a default mode of 755. -
installcan be configured to set the file's owner or group and/or the file's mode. -
installcan be configured to back up the original file before it is replaced. -
ddis a low-level copy tool, mainly used to copy blocks of an exactly specified size from a source (e.g. a file or device). -
cpis the common command for copying files; with the-roption it copies directories recursively, and with the-poption it preserves permissions. -
installis mostly similar tocp, but additionally provides options to set the destination file's properties directly without having to usechmodseparately. - The
installcommand is typically used in installation scripts that come with packages and source code to install binaries onto the system.- It can also be used to install other files or directories.
- Besides the
-dand-coptions, there is the-moption for specifying the new permissions of the file being installed, so you don't need to runcpandchmodto get the same result.
-g and -o options for setting the target group and owner, respectively.- This avoids separate
chowncalls. - In general, using
installlets you perform file creation, copying, mode setting, and related tasks with one command instead of many, making scripts shorter and more concise.
Example comparing with cp:
# cp를 사용하는 경우
cp myapp /usr/local/bin/
chmod 755 /usr/local/bin/myapp
chown root:root /usr/local/bin/myapp
# install을 사용하는 경우 (한 줄로 가능)
install -m 755 -o root -g root myapp /usr/local/bin/
Examples
# Example 1: 실행 파일 설치 (권한 755)
install -m 755 myapp /usr/local/bin/
# Example 2: 설정 파일 설치 (권한 644)
install -m 644 config.conf /etc/myapp/
# Example 3: 디렉토리 생성과 동시에 파일 설치
install -D -m 755 myapp /opt/myapp/bin/myapp
# Example 4: 여러 파일을 한 번에 설치
install -m 644 file1.txt file2.txt file3.txt /usr/share/doc/myapp/
# Example 5: 소유자와 그룹 지정
install -m 644 -o www-data -g www-data index.html /var/www/html/
# Example 6: 디렉토리만 생성 (권한 755)
install -d -m 755 /opt/myapp/{bin,lib,share}
# Example 7: 백업 생성하면서 설치
install -b -m 644 config.conf /etc/myapp/config.conf
# Scenario 1: Python 스크립트 시스템 전역 설치
install -m 755 myscript.py /usr/local/bin/myscript
# Scenario 2: 라이브러리 파일 설치
install -m 644 libmylib.so /usr/local/lib/
ldconfig # 라이브러리 캐시 업데이트 / Update library cache
# Scenario 3: systemd 서비스 파일 설치
install -m 644 myapp.service /etc/systemd/system/
systemctl daemon-reload
# Scenario 4: 안전한 설치 (비교 후 복사)
install -C -m 644 config.conf /etc/myapp/config.conf
Makefile
# Makefile install target example
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
DATADIR = $(PREFIX)/share/myapp
install:
# Install binary / 바이너리 설치
install -D -m 755 myapp $(BINDIR)/myapp
# Install data files / 데이터 파일 설치
install -D -m 644 data/config.ini $(DATADIR)/config.ini
# Create directory / 디렉토리 생성
install -d -m 755 $(DATADIR)/plugins
See also
Pages that link here