新安装的软件配置环境变量,方便以后使用
直接利用echo 'PATH=$PATH:/安装位置' >>添加到~/.bashrc文件中是可以用的。下面图片中是鸟哥的配置文件访问示意图,我可不可以这么说,反正最后访问的是~/.bashrc这个文件,那么我把所有的偏好设置,包括环境变量的配置放到这里面就可以了?
那么我是不是还可以这么说,像java这种系统环境配置,我就要放到一开始访问的/etc/profile中才可以?
我是linux小白,只懂一些操作却对其中的意义了解的很肤浅
请各位大神指点一下

解决方案 »

  1.   

    /etc/profile是系统环境变量,对所有用户有效
    ~/.bashrc这个是对当前账号有效(~是指当前账号的家目录)
      

  2.   

    谢谢大哥!一句话点醒我,我再问您一个问题,我把java配置到/etc/profile中了,但是会导致命令失效开机重启等,那我不考虑别的用户,我只是自己的用户使用,我把java配置到~/.bashrc中可以吗?java还会生效吗?
      

  3.   

    谢谢大哥!一句话点醒我,我再问您一个问题,我把java配置到/etc/profile中了,但是会导致命令失效开机重启等,那我不考虑别的用户,我只是自己的用户使用,我把java配置到~/.bashrc中可以吗?java还会生效吗?可以加到~/.bashrc
      

  4.   

    谢谢大哥!一句话点醒我,我再问您一个问题,我把java配置到/etc/profile中了,但是会导致命令失效开机重启等,那我不考虑别的用户,我只是自己的用户使用,我把java配置到~/.bashrc中可以吗?java还会生效吗?可以加到~/.bashrc
    谢谢大哥,对于我这种小白发表一个帖子问问题您能这么快回复我我太感动了
      

  5.   

    谢谢大哥!一句话点醒我,我再问您一个问题,我把java配置到/etc/profile中了,但是会导致命令失效开机重启等,那我不考虑别的用户,我只是自己的用户使用,我把java配置到~/.bashrc中可以吗?java还会生效吗?可以加到~/.bashrc
    可是现在还有个问题,我加到~/.bashrc中java好像没有用诶是必须要加到/etc/profile中吗
      

  6.   

    加完之后  你有source ~/.bashrc吗 重新加载文件
      

  7.   

    source了,不管用,虽然我知道可以在ubunt上利用apt-get install jar来安装java环境,但是我还是想明白其中的道理,为什么把自己下载的java配置在~/.bashrc中不管用,而配置在/etc/profile中就管用,是因为他最开始调用的是/etc/profile这个文件吗?属于login shall而nologinshall就不行?
      

  8.   

    source了,不管用,虽然我知道可以在ubunt上利用apt-get install jar来安装java环境,但是我还是想明白其中的道理,为什么把自己下载的java配置在~/.bashrc中不管用,而配置在/etc/profile中就管用,是因为他最开始调用的是/etc/profile这个文件吗?属于login shall而nologinshall就不行?
    看下你的.bashrc文件
      

  9.   

    # ~/.bashrc: executed by bash(1) for non-login shells.# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)# for examples# If not running interactively, don't do anythingcase $- in    *i*) ;;      *) return;;esac# don't put duplicate lines or lines starting with space in the history.# See bash(1) for more optionsHISTCONTROL=ignoreboth# append to the history file, don't overwrite itshopt -s histappend# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)HISTSIZE=1000HISTFILESIZE=2000# check the window size after each command and, if necessary,# update the values of LINES and COLUMNS.shopt -s checkwinsize# If set, the pattern "**" used in a pathname expansion context will# match all files and zero or more directories and subdirectories.#shopt -s globstar# make less more friendly for non-text input files, see lesspipe(1)[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"# set variable identifying the chroot you work in (used in the prompt below)if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then    debian_chroot=$(cat /etc/debian_chroot)fi# set a fancy prompt (non-color, unless we know we "want" color)case "$TERM" in    xterm-color|*-256color) color_prompt=yes;;esac# uncomment for a colored prompt, if the terminal has the capability; turned# off by default to not distract the user: the focus in a terminal window# should be on the output of commands, not on the prompt#force_color_prompt=yesif [ -n "$force_color_prompt" ]; then    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes    else color_prompt=    fifiif [ "$color_prompt" = yes ]; then    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 'else    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 'fiunset color_prompt force_color_prompt# If this is an xterm set the title to user@host:dircase "$TERM" inxterm*|rxvt*)    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"    ;;*)    ;;esac# enable color support of ls and also add handy aliasesif [ -x /usr/bin/dircolors ]; then    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"    alias ls='ls --color=auto'    #alias dir='dir --color=auto'    #alias vdir='vdir --color=auto'    alias grep='grep --color=auto'    alias fgrep='fgrep --color=auto'    alias egrep='egrep --color=auto'fi# colored GCC warnings and errors#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'# some more ls aliasesalias ll='ls -alF'alias la='ls -A'alias l='ls -CF'alias h='history'alias myip="ifconfig enp3s0f1 | grep 'inet'| sed -e '2d' -e 's/^.*inet/ /g' | cut -d ' ' -f 3"MYIP=$(myip)# Add an "alert" alias for long running commands.  Use like so:#   sleep 10; alertalias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'# Alias definitions.# You may want to put all your additions into a separate file like# ~/.bash_aliases, instead of adding them here directly.# See /usr/share/doc/bash-doc/examples in the bash-doc package.if [ -f ~/.bash_aliases ]; then    . ~/.bash_aliasesfi# enable programmable completion features (you don't need to enable# this, if it's already enabled in /etc/bash.bashrc and /etc/profile# sources /etc/bash.bashrc).if ! shopt -oq posix; then  if [ -f /usr/share/bash-completion/bash_completion ]; then    . /usr/share/bash-completion/bash_completion  elif [ -f /etc/bash_completion ]; then    . /etc/bash_completion  fifiPATH=$PATH:~/d/software/biosoft/sratoolkit/sratoolkit.2.9.6-1-ubuntu64/bin# >>> conda initialize >>># !! Contents within this block are managed by 'conda init' !!__conda_setup="$('/home/rock/d/software/biosoft/anaconda/[/home/rock/d/software/biosoft/anaconda]/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"if [ $? -eq 0 ]; then    eval "$__conda_setup"else    if [ -f "/home/rock/d/software/biosoft/anaconda/[/home/rock/d/software/biosoft/anaconda]/etc/profile.d/conda.sh" ]; then        . "/home/rock/d/software/biosoft/anaconda/[/home/rock/d/software/biosoft/anaconda]/etc/profile.d/conda.sh"    else        export PATH="/home/rock/d/software/biosoft/anaconda/[/home/rock/d/software/biosoft/anaconda]/bin:$PATH"    fifiunset __conda_setup# <<< conda initialize <<<PATH=$PATH:~/d/software/biosoft/anaconda/anaconda/binPATH=$PATH:~/d/software/biosoft/HISAT/hisat-0.1.6-betaPATH=$PATH:~/d/software/biosoft/fastqc/FastQCPATH=$PATH:~/d/software/biosoft/samtools/bin
      

  10.   

    source了,不管用,虽然我知道可以在ubunt上利用apt-get install jar来安装java环境,但是我还是想明白其中的道理,为什么把自己下载的java配置在~/.bashrc中不管用,而配置在/etc/profile中就管用,是因为他最开始调用的是/etc/profile这个文件吗?属于login shall而nologinshall就不行?
    看下你的.bashrc文件
    内容有点多老哥,再评论区里面
      

  11.   

    source了,不管用,虽然我知道可以在ubunt上利用apt-get install jar来安装java环境,但是我还是想明白其中的道理,为什么把自己下载的java配置在~/.bashrc中不管用,而配置在/etc/profile中就管用,是因为他最开始调用的是/etc/profile这个文件吗?属于login shall而nologinshall就不行?
    看下你的.bashrc文件
    内容有点多老哥,再评论区里面这是.bashrc吗  怎么这么多?
    你就在配置文件最后加上   
    export JAVA_HOME=/***/***
    export PATH=$PATH:$JAVA_HOME/bin
      

  12.   

    source了,不管用,虽然我知道可以在ubunt上利用apt-get install jar来安装java环境,但是我还是想明白其中的道理,为什么把自己下载的java配置在~/.bashrc中不管用,而配置在/etc/profile中就管用,是因为他最开始调用的是/etc/profile这个文件吗?属于login shall而nologinshall就不行?
    看下你的.bashrc文件
    内容有点多老哥,再评论区里面这是.bashrc吗  怎么这么多?
    你就在配置文件最后加上   
    export JAVA_HOME=/***/***
    export PATH=$PATH:$JAVA_HOME/bin
    没错是.bashrc,好的大哥我试试,谢谢啦