Astephen2
Astephen2

Reputation: 851

Symlink ~.zshrc

If my .zshrc file is ~/.dotfiles/zsh/.zshrc, how can I create a symlink so that the file appears as ~/.zshrc?

Upvotes: 19

Views: 17331

Answers (5)

Cooper Runyan
Cooper Runyan

Reputation: 84

On MacOS, you can't use ~ in a symlink where the directory is quoted. You need to use full paths. I'd recommend running ln -s "$HOME/.dotfiles/zsh/.zshrc" "$HOME/.zshrc" Alternatively, you can forget the quotes, and use ~ in place of $HOME, however if there are any spaces (or variables with spaces) you'll probably run into problems.

Upvotes: 0

chepner
chepner

Reputation: 531325

You don't actually need a symlink. Add the following to ~/.zshenv:

ZDOTDIR=~/.dotfiles/zsh

zsh sources ~/.zshenv before any other files, and will use the value of $ZDOTDIR as the location for local configuration files in lieu of your home directory.

Upvotes: 0

lehanh
lehanh

Reputation: 585

for me, when using relative path for symlink, it can show error: ~/.zshrc: No such file or directory error as @astephen2. You should change to absolute path then it working fine

Upvotes: 0

Aaron Cronin
Aaron Cronin

Reputation: 2103

The cd step in Alexej's answer isn't needed as you can call ln -s target destination explicitly.

ln -s ~/.dotfiles/zsh/.zshrc ~/.zshrc

Upvotes: 31

Alexej Magura
Alexej Magura

Reputation: 5119

run:

cd ~/ ; ln -s ~/.dotfiles/zsh/.zshrc

Upvotes: 4

Related Questions