環境變量設置的幾種方法


一、CentOS

在CentOS系統中添加環境變量的方法有幾種,推薦第三種方法。這里以添加 TexLive 2017 的環境變量為例進行說明。

 

1. 修改  ~/.bash_profile  文檔,在文末添加以下代碼:

$ vi ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

# path for TexLive 2017
export TEXMF=/usr/local/texlive/texmf-local export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2017/bin/x86_64-linux export MANPATH=$MANPATH:/usr/local/texlive/2017/texmf-dist/doc/man export INFOPATH=$INFOPATH:/usr/local/texlive/2017/texmf-dist/doc/info
$ source ~/.bashrc  # 在終端運行相應的變量更新,即可得到更新后的環境變量

 

 

2. 修改  ~/.bashrc  文檔,在文末添加以下內容:

$ vi ~/.bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

# path for TexLive 2017
export TEXMF=/usr/local/texlive/texmf-local export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2017/bin/x86_64-linux export MANPATH=$MANPATH:/usr/local/texlive/2017/texmf-dist/doc/man export INFOPATH=$INFOPATH:/usr/local/texlive/2017/texmf-dist/doc/info

$ source ~/.bashrc  # 在終端運行相應的變量更新,即可得到更新后的環境變量

 

3. 新建一個 shell 文件,命名為 ~/TexLive2017.sh ,它的內容如下,並將它拷貝到目錄  /etc/profile.d/  下。

在終端運行相應的變量更新,即可得到更新后的環境變量。

$ vi ~/TexLive2017.sh
#!/bin/bash
# setting for TexLive 2017 environment variables, edit by She
export TEXMF=/usr/local/texlive/texmf-local
export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/texlive/2017/bin/x86_64-linux
export MANPATH=$MANPATH:/usr/local/texlive/2017/texmf-dist/doc/man
export INFOPATH=$INFOPATH:/usr/local/texlive/2017/texmf-dist/doc/info

$ source /etc/profile.d/texlive2017.sh 

 

二、Mac

參考這里:https://blog.csdn.net/u010596262/article/details/103155283

 

之前配置環境變量一直都在 ~/.bash_profile 中, 最近更新系統后,重啟終端后或者重啟系統環境變量配置都不生效。

每次都需要重新執行 : $source ~/.bash_profile。

 

zsh加載的是 ~/.zshrc文件

在~/下新建 .zshrc 文件,並在里面添加一行:source ~/.bash_profile

保存~/.zshrc文件,重啟后,一切正常。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM