본문 바로가기
목차
Linux

[zsh] install Zsh and oh-my-zsh:

by ds31x 2023. 9. 11.
728x90
반응형

Zsh 란?

Zsh는 1990년에 출시된 유닉스 셸 및 명령어 인터프리터:

  • bash, ksh, tcsh 등 다른 셸의 가장 유용한 기능들을 통합하고 풍부한 테마와 플러그인 생태계를 통해 강력한 사용자 경험을 제공.
  • 특히 자동 완성, 히스토리 관리, 테마 지원 등 강화된 기능 덕분에 개발자와 고급 사용자들 사이에서 인기가 많음.

 

macOS에서는 Zsh가 기본셀 이며 개인용 장비에선 그 사용률이 증가하고 있음.

서버 장비에선 bash가 거의 표준이나, 테스트 장비에선 zsh의 사용률임.


Prompt Theme Engine

oh-my-zsh 와 같이 사용되면서 prompt 가 매우 효율적이 됨(이쁘기도하고...)

oh-my-zsh이나 oh-my-posh는
shell 터미널 환경을 쉽게 customizing 할 수 있도록
여러 테마와 플러그인으로 구성된 오픈소스 프레임워크임.
shell framework 또는 prompt theme engine이라고 불림.

oh-my-posh 는

  • Zsh 외의 여러 shell에서 사용가능한 cross platform prompt engine이나,
  • power shell에서의 속도가 꽤 느린 편이다.
Zsh 이 사용가능하다면
oh-my-zsh 을 적극 추천함.

 

Windows라면 wsl을 제외하곤 oh-my-posh를 선택할 수 밖에 없음.

 

참고: 2023.06.20 - [개발환경] - [Env] Oh-My-Posh

 

[Env] Oh-My-Posh

Oh-My-Posh는 Command Line Interface(cli)에서 prompt 부분을 customize할 수 있게 해주는 custom prompt engine이다. 유사한 것으로는 Oh-My-Zsh 이 있음 (사실 oh-my-zsh이 먼저고 이를 bash등에서 가능하도록 만들어준 것

ds31x.tistory.com

2025.10.11 - [utils/cmd and powershell] - Windows에서 Oh-My-Posh 설치하기

 

Windows에서 Oh-My-Posh 설치하기

Windows 외의 OS에서는 Oh My Zsh 를 권장. Windows에서의 설치는 winget 을 이용하길 권함:2024.09.08 - [utils] - [Utils] winget 간단 사용법 [Utils] winget 간단 사용법winget은 CLI Windows Package Manager임.SW 설치,업데이트

ds31x.tistory.com


테스트한 설치 환경

Ubuntu 22.04.3 LTS

zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

 

참고 문서: Installing ZSH · ohmyzsh/ohmyzsh Wiki (github.com)

 

Installing ZSH

🙃 A delightful community-driven (with 2,300+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, pyth...

github.com


zsh 설치 및 기본 셀 변경

아래 명령어로 zsh 설치.

sudo apt install zsh

/etc/passwd에서 원하는 계정의 shell을 /bin/zsh로 변경.

 

shell을 변경하는 방법은 다음 글을 참고.

2023.09.08 - [Linux] - [zsh] 사용자 Shell 확인 및 변경하기.

 

[zsh] 사용자 Shell 확인 및 변경하기.

사실 linux를 따로 배운 적이 없이, 업무 중에 조금씩 익혀나간터라...무엇이 가장 권장되는 방법인지는 자신이 없다. ==;;가장 쉬운 방법은 환경변수 SHELL을 확인하는 것임.echo ${SHELL}환경변수가 아

ds31x.tistory.com


이후 터미널을 재시작하면 다음과 같이 zsh를 설정화면이 뜸:

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses ---
  • oh-my-zsh를 설치할 예정이므로 0을 선택하여 일단 ~/.zshrc파일을 생성만 한다.
  • exec zsh로 현재 셸을 zsh로 변경하거나 다시 로그인하길 권함.


Homebrew 설치하기

macOS 유저들에겐 매우 익숙한 package manager임.

winget과 homebrew는 개인용 장비에서 가장 편한 package manager임.

 

이후 설치할 것들을 위해 다음 url을 따라 homebrew와 필수 패키지, 라이브러리를 설치한다.

2023.09.05 - [Linux] - [Linux] homebrew 설치하기 (Ubuntu)

 

[Linux] homebrew 설치하기 (Ubuntu)

Homebrew는 Max Howell이 만든 패키지 관리자 (Debian 계열 linux의 apt-get 또는 Windows 의 winget과 비슷)임.macOS 용 으로 2009년 ruby로 개발됨.사실상 macOS에서는 표준 패키지 관리자임.최근 들어 linux 및 WSL에서

ds31x.tistory.com


oh-my-zsh 설치

다음 명령어로 oh-my-zsh를 설치.

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
  • wget이 없으면 동작하지 않음.
  • 이 경우 sudo apt install wget으로 먼저 wget을 설치하고 수행.

다음과 같은 화면이 보임.

--2023-09-11 11:57:40--  https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8001::154, 2606:50c0:8002::154, 2606:50c0:8003::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8001::154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18209 (18K) [text/plain]
Saving to: ‘STDOUT’

-                     100%[========================>]  17.78K  --.-KB/s    in 0s

2023-09-11 11:57:40 (102 MB/s) - written to stdout [18209/18209]

Cloning Oh My Zsh...
remote: Enumerating objects: 1358, done.
remote: Counting objects: 100% (1358/1358), done.
remote: Compressing objects: 100% (1306/1306), done.
remote: Total 1358 (delta 33), reused 1122 (delta 28), pack-reused 0
Receiving objects: 100% (1358/1358), 2.00 MiB | 10.04 MiB/s, done.
Resolving deltas: 100% (33/33), done.
From https://github.com/ohmyzsh/ohmyzsh
 * [new branch]      master     -> origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Already on 'master'
/home/ubuntu

Looking for an existing zsh config...
Found /home/ubuntu/.zshrc. Backing up to /home/ubuntu/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to /home/ubuntu/.zshrc.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh

➜  ~

이제 oh-my-zsh의 테마와 plugin들을 설치해야한다.

그 전에 이들을 쉽게 설치하기 위해 homebrew를 설치한다.


NerdFont설치하기

테마를 제대로 사용하려면 우선 NerdFont와 같은 icon등을 지원하는 font설치가 필요하다.
font 설치는 다음 글을 참고하라.

2023.07.14 - [개발환경] - [Env] Install a NerdFont on Ubuntu

 

[Env] Install a NerdFont on Ubuntu

brew로 설치하기 (추천)brew install --cask font-caskaydia-cove-nerd-font macOS에선 어지간한 건 brew 로 다 된다.직접 다운로드 받아 font config로 설치하기--;; brew가 편해...순서원하는 Nerd Font 를 다운로드.압축을

ds31x.tistory.com


powerlevel10k 테마로 변경.

oh-my-zsh는 다양한 테마를 제공한다.
개인적으로 powerlevel10k를 가장 애용한다.

https://github.com/romkatv/powerlevel10k

 

GitHub - romkatv/powerlevel10k: A Zsh theme

A Zsh theme. Contribute to romkatv/powerlevel10k development by creating an account on GitHub.

github.com

 

다음 명령어로 powerlevel10k를 clone을 수행.

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

 

다운로드받은 powerlevel10k를 적용하기 위해 ~/.zshrc를 수정.

sudo vi ~/.zshrc
  • 초보자라면 vi보다 nano를 사용하라.

https://dsaint31.tistory.com/473

 

[Linux] vi 사용법 정리

이동관련 기본이동 (Normal mode에서) h : 왼쪽으로 한 글자 이동. j : 한 행 아래로. k : 한 행 위로. l : 오른쪽으로 한 글자 이동. 화면내 이동 H : 현재 화면에서 가장 위의 행으로 M : 현재 화면에서 가

dsaint31.tistory.com

https://dsaint31.tistory.com/444

 

[Linux] nano Editor 간단 사용법

주로 vi만 사용하기 때문에 nano는 그닥...문제는 다른 사람 장비에서 간단한 일을 할 때, vi가 없는 경우가 있고, editor 지정을 vi로 바꾸며 원래 주인이 답답해하는 경우가 발생한다. (그렇다고 매

dsaint31.tistory.com

 

해당 파일에서 ZSH_THEME 를 설정하는 라인을 찾고 다음으로 변경.

ZSH_THEME="powerlevel10k/powerlevel10k"

이후 다음 명령어를 수행하면 powerlevel10k 테마 설정이 시작됨.

source ~/.zshrc
  • 설정에서 주로 icon 문자가 제대로 보이는지를 물어본다.
  • 개인적으로 unicode, twoline과 round 등의 스타일을 애용함.
  • p10k configure를 수행하면 재설정이 가능하니 너무 부담을 가지지 않아도 된다.

설정 첫화면은 다음과 같음 (가운데의 diamond 문자가 보이는지를 물어봄).


설정을 다하고 나면, oh-my-zsh에 적용이 된 다음과 같은 화면을 볼 수 있음.


환경 설정파일들 편집

이후, ~/.bashrc에서 conda 등의 설정을 ~/.zshrc에 똑같이 기재해주면 된다.
~/.bash_profile에 있는 내용은 다음 글을 참고하여 ~/.zprofile에 적용시킨다.

(참고로 bash에선 .bash_profile이 가장 우선순위이고, 없으면 .bash_login, 또 없으면 .profile 순으로 읽는다: 우선순위가 높은 하나만 읽음)

2023.09.08 - [개발환경] - [zsh] .profile의 설정을 .zprofile로 ...

 

[zsh] .profile의 설정을 .zprofile로 ...

WSL2의 Ubuntu에서 shell을 bash에서 zsh로 변경하기로 했다. oh-my-posh에 비해, oh-my-zsh가 속도등의 측면에서 빠른 점이 있었고...bash만 계속 사용한 듯 해서 개인용 노트북에서는 zsh도 한번 사용해봐야지

ds31x.tistory.com


zsh에서 자주 사용되는 Plug-in 설치

~/.zshrc 파일에서 plugins 을 찾아서 다음과 같이 sudocolored-man-pages를 추가해준다.

plugins=(
        git
        sudo
        colored-man-pages
)

sudo 의 경우, 명령어를 입력하다 esc를 두번 누르면 앞에 sudo가 붙여주는 플러그인임: zsh-vi-mode 와 같이 쓰지 않는게 나음.

colored-man-pages 의 경우, man으로 명령어에 대한 메뉴얼을 볼 때 highlighting이 되어 보다 읽기 쉽게 해줌.

 

이외에도 많이 사용되는 plugin은 zsh-syntax-highlightingzsh-autosuggestions 등이 있음.

(oh-my-zsh의 plugin 설치하는 방법이 아닌 brew로 해결하는 방법을 취함. brew연습을 겸해서...)

 

2023.09.08 - [개발환경] - [zsh] zsh-syntax-highlighting 설치.

 

[zsh] zsh-syntax-highlighting 설치.

Ubuntu에서 zsh와 homebrew를 설치하면서 같이 설치했다. Windows Terminal과 Nerd Font, oh-my-zsh와 같이 사용하니 터미널이 아주 화사해졌다. (집은 인테리어 문제로 시멘트 나오고 물에 젖은 바닥 등 엉망인

ds31x.tistory.com

 

2023.09.08 - [개발환경] - [zsh] zsh-autosuggestions

 

[zsh] zsh-autosuggestions

zsh에서 history를 기반으로 최근 입력한 명령어를 일종의 미리보기 형태로 추천해주는 기능을 제공한다. 방향키를 통해 command를 쉽게 입력할 수 있다. 관련 공식 사이트는 다음과 같음:https://github.

ds31x.tistory.com

 

2026.01.06 - [Linux] - [zsh] zsh-vi-mode 설치 및 사용법

 

[zsh] zsh-vi-mode 설치 및 사용법

1. zsh-vi-mode 란?Zsh에서 Vim의 Normal / Insert 모드 개념을 그대로 사용할 수 있게 해주는 플러그인기본 vi keymap(bindkey -v) 대비 다음과 같은 장점이 있음모드 전환을 명확히 인지 가능커서 스타일 변경

ds31x.tistory.com


 

728x90