CENTOS 7-安装JDK后$ PATH错误 [英] CENTOS 7 - $PATH incorrect after installing jdk

查看:93
本文介绍了CENTOS 7-安装JDK后$ PATH错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Linux操作系统的新手,并且已在centos7上安装了jdk.

I'm new with Linux OS and I have installed jdk on centos7.

现在,每次我登录时,都会收到以下错误消息:

Now each time I login, I get following error message:

/usr/libexec/grepconf.sh: line 5: grep: command not found
-bash: /home/centos/.bash_profile: line 13: syntax error near unexpected token `newline'
-bash: /home/centos/.bash_profile: line 13: `export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>'

所有命令均未找到"

我找到此信息以更新路径: https://unix.stackexchange.com/questions/302743/centos-7-所有命令都找不到-除了cd

I find this post to update path: https://unix.stackexchange.com/questions/302743/centos-7-all-command-not-found-except-cd

然后我用以下命令更新路径:

and I update path with this command:

PATH=/usr/local/bin:/usr/bin:bin

所以现在 sudo nano/home/centos/.bash_profile 命令,我在bash_profile文件中具有以下内容:

So now with sudo nano /home/centos/ .bash_profile command I have following content in bash_profile file:

# .bash_profile

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

 # User specific environment and startup programs

 PATH=$PATH:$HOME/.local/bin:$HOME/bin

 export PATH
 export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep>

什么是问题?我该如何解决所描述的错误?

What is problem ? How can I solve the error described ?

第一次编辑,以回答@航海问题:

1rst edit in order to answer @nautical questions:

.bash_profile文件的内容:

Here the content of .bash_profile file :

# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH
export PATH=$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep

这里是grepconf的内容:

Here the content of grepconf :

#!/bin/sh

case "$1" in
    -c | --interactive-color)
        ! grep -qsi "^COLOR.*none" /etc/GREP_COLORS
        ;;
    *)
        echo >&2 "Invalid / no option passed, so far only -c | --interactive-color is supported."
        exit 1
        ;;
esac

第二次编辑,以回答评论中的问题:

2nd Edit in order to answer questions in comment :

这里ldd/usr/bin/grep命令输出:

here ldd /usr/bin/grep command output:

linux-vdso.so.1 =>  (0x00007fff769b8000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f0454df3000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f0454a26000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0454809000)
    /lib64/ld-linux-x86-64.so.2 (0x000055ce09e0c000)

这是ls -l/lib64/ld *的结果

Here the result of ls -l /lib64/ld*

[centos@serveur-1 ~]$ ls -l /lib64/ld*
-rwxr-xr-x 1 root root 163400 Jan 29 18:55 /lib64/ld-2.17.so
lrwxrwxrwx 1 root root     10 Feb 20 21:51 /lib64/ld-linux-x86-64.so.2 -> ld-2.17.so

每次我注销后,我都会登录,除了某些命令,我​​总是得到找不到命令":

And each time I logout, then I login, I get always "command not found" except for some command like for example :

java -version

因此,每次我必须键入"PATH =/usr/local/bin:/usr/bin:bin/"(在此站点上找到答案),并且每次我键入echo $ PATH时,输出都会越来越复杂:

So each time I must type "PATH=/usr/local/bin:/usr/bin:bin/" (answer found on this site) and each time I type echo $PATH, the output is more and more complex :

[centos@serveur-1 ~]$ echo $PATH
$PATH:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin:/usr/bin/grep

我想$ PATH内容刚登录后就坏了.

I suppose $PATH content is bad just after login.

那我该如何彻底解决呢?

So how can I solved it definitively ?

对@tripleee的第三次修改:这里的.bashrc文件内容:

Third edit for @tripleee : Here .bashrc file content :

[centos@serveur-1 ~]$ sudo nano /home/centos/.bashrc
  GNU nano 2.3.1                  File: /home/centos/.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

它谈论/etc/bashrc,所以这是它的内容:

It talks about /etc/bashrc, so this is its content:

[centos@serveur-1 ~]$ sudo nano /etc/bashrc
  GNU nano 2.3.1                   File: /etc/bashrc

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOM$
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-de$
      ;;
    esac
  fi
  # Turn on parallel history
  shopt -s histappend
  history -a
  # Turn on checkwinsize
  shopt -s checkwinsize
  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
  # You might want to have e.g. tty in prompt (e.g. more virtual machines)
  # and console windows
  # If you want to do so, just add e.g.
  # if [ "$PS1" ]; then
  #   PS1="[\u@\h:\l \W]\\$ "
  # fi
  # to your custom modification shell script in /etc/profile.d/ directory
fi

if ! shopt -q login_shell ; then # We're not a login shell
    # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
        case ":${PATH}:" in
            *:"$1":*)
                ;;
            *)
                if [ "$2" = "after" ] ; then
                    PATH=$PATH:$1
                else
                    PATH=$1:$PATH
                fi
        esac
    }

    # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; 

then
       umask 002
    else
       umask 022
    fi

    SHELL=/bin/bash
    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . "$i"
            else
                . "$i" >/dev/null
            fi
        fi
    done

    unset i
    unset -f pathmunge
fi
# vim:ts=4:sw=4

当您来自"Windows世界"时,很难理解这种机制.

It's quite difficult to understand this mechanism when you come from "Windows world"...

推荐答案

通过如下更新.bash_profile来解决:

Solved by updating .bash_profile as following:

# .bash_profile

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

# User specific environment and startup programs 


PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin:/usr/bin:/bin:/opt/jdk1.8.0_192/bin:/opt/jdk1.8.0_192/jre/bin

export PATH

我是Centos的新手,所以我希望我能获得2分(经否决票删除):

I'm new with Centos so I hope I will retrieve my 2 points (removed by negative vote):

  • 我已经编辑了问题并整理了结构,以便回答评论中提出的问题
  • 我一直在寻找答案(请参阅链接),但我不理解所有说明,因此可能很难弄清楚

这篇关于CENTOS 7-安装JDK后$ PATH错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆