I was trying to transfer my terminal setup (iTerm2, zsh, oh-my-zsh, omz themes) from an old MacBook to a new one.

.zshrc real file is in Dropbox shared between the two laptops, and in each laptop there's a ~/.zshrc symlink to the Dropbox one.

With this setup, I encountered this error in the new laptop:

someuser@Someusers-MacBook-Pro ~ % source ~/.zshrc
/Users/someuser/.zshrc:source:78: no such file or directory: ~/.oh-my-zsh/oh-my-zsh.sh
/Users/someuser/.zshrc:source:112: no such file or directory: /Users/someuser/.rcsource
someuser@Someusers-MacBook-Pro ~ % ls  ~/.oh-my-zsh/oh-my-zsh.sh
someuser@Someusers-MacBook-Pro ~ % cat ~/.zshrc | grep oh-my-zsh
# Path to your oh-my-zsh installation.
export ZSH="~/.oh-my-zsh"
# load a random theme each time oh-my-zsh is loaded, in which case,
source $ZSH/oh-my-zsh.sh

As you can see, the output doesn't make any sense. It complains about not being able to find ~/.oh-my-zsh/oh-my-zsh.sh yet when I do ls on that path, it shows that it exists.


The tilde ~ in a parameter does not expanded by default, only when the option GLOB_SUBST is set, see man zshoptions. Maybe this option is hidden somewhere in your old (global) config, e.g. in /etc/zshrc.

So, to give some examples:

$ foo="~/.zshrc"
$ ls $foo
ls: cannot access '~/.zshrc': No such file or directory
$ ls ${~foo}
$ setopt GLOB_SUBST
$ ls $foo

The syntax ${~foo} temporarily enables GLOB_SUBST for the current expansion, see PARAMETER EXPANSION in man zshexpn.

So, to cut a long story short: The simplest solution is to replace ~ in the line export ZSH="~/.oh-my-zsh" with /Users/someuser.


~ is a shell shorthand for your home directory, not part of an actual valid path. In some situations, the shell will expand ~ into the actual path, but not if it's in quotes. Just replace this:

export ZSH="~/.oh-my-zsh"    # Doesn't work because ~ is quoted

with either this:

export ZSH=~/.oh-my-zsh    # No quotes, so ~ expands to home directory path

or this:

export ZSH="$HOME/.oh-my-zsh"    # Parameters do expand in double-quotes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.