Mac .zshrc 写入环境变量时被覆盖了如何恢复?

题目描述

错误的使用了写入命令

export GOPATH=$HOME/go > .zshrc

导致我的.zshrc文件空了,不过我没有执行 source .zshrc,但是打开其他的终端我的命令已经失效了

期待的结果

恢复我的.zshrc

阅读 5.4k
3 个回答

貌似无法恢复,你这样直接覆盖了。

至于source .zshrc仅仅是是否使当前.zshrc直接生效,并不会有啥影响。

你可以在其他未关闭的终端echo $PATH 看一下历史的路径


复制了一下我的供你参考

MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH
export PATH=/usr/local/Cellar/redis/3.2.6/bin:$PATH
export PATH=/usr/local/sbin:$PATH
export PATH=$HOME/.composer/vendor/bin:$PATH
#export PATH=/Users/lpe234/hadoop-2.7.3/bin:$PATH
#export HADOOP_HOME=/Users/lpe234/hadoop-2.7.3

# ANDROID_HOME
ANDROID_HOME=/Users/lpe234/Library/Android/sdk
export ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

# jmeter
export PATH=$PATH:/Applications/apache-jmeter-5.4/bin

# Scala
export SCALA_HOME=/usr/local/opt/scala/idea

export HOMEBREW_GITHUB_API_TOKEN="8076c45f558ab76a21c6bca84b5aeb156b054cd4"

# flutter
export PATH=`pwd`/flutter/bin:$PATH

# Pods
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
# Go path
export GOROOT=/usr/local/Cellar/go/1.15/libexec
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN
export GO111MODULE=on
export GOPROXY=https://goproxy.io


export JIRA_HOME=/Users/lpe234/atlassian-jira-software-7.3.1-standalone/jira-home

# Path to your oh-my-zsh installation.
export ZSH=/Users/lpe234/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git brew zsh-autosuggestions zsh-completions zsh-syntax-highlighting)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"
alias killtomcat="ps aux | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill"

alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'

eval $(thefuck --alias)
export PATH="/usr/local/opt/cython/bin:$PATH"
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export PATH="/usr/local/opt/curl/bin:$PATH"



export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
alias readlink=greadlink

export PATH="/usr/local/opt/curl/bin:$PATH"


alias confd=confd-0.16.0-darwin-amd64

alias cls=clear

alias fixusb="killall -STOP -c usbd"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion







#export JAVA_HOME=/usr/libexec/java_home
#export JAVA_HOME=/Users/lpe234/.jenv/shims/
export PATH="/usr/local/opt/opencv@3/bin:$PATH"


export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

export PATH=/Users/lpe234/flutter/bin:$PATH


export PATH="/usr/local/opt/ruby/bin:$PATH"

export PATH="/Library/Apple/usr/bin/:$PATH"
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

本文参与了SegmentFault 思否面试闯关挑战赛,欢迎正在阅读的你也加入。
新手上路,请多包涵

vi ~/.zshrc, (不要sudo)

Swap file "~/.zshrc.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

选择:(R)ecover 恢复

或者看下 ~/.zshrc.swp 文件里面内容还在不在

新手上路,请多包涵

在你还没有关闭的终端,执行env
抢救被你删除的环境变量,如http_proxy,PATH,Conda等等

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏