Mac无法启动RocketMQ,日志显示,runserver.sh: line 91: /Library/Internet: No such file or directory

前言

从日志的报错信息可以看出, /Library/Internet 大概率是因为系统安装的jdk路径包含空格导致脚本启动失败

为什么能看出来是 jdk 路径的问题, 那是因为遇到这种问题多了, 基本上也知道哪里会问题
特别是因为中间升级了 mac 的系统, 那各种问题都有, 都想回退系统版本了

解决办法

一. 改系统配置文件

1. 系统配置: /etc/profile

  • 能改, 但对于高版本的 mac 系统, 改了也生效不了, 除非一些特别的操作, 个人觉得风险太大, 没有继续尝试

2. 用户配置: ~/.bash_profile

  • 使用 vim 命令打开 ~/.bash_profile, 在文件最后, 添加如下内容
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
  • 让改动生效(命令): source ~/.bash_profile

查询自己mac安装的各类jdk路径
/usr/libexec/java_home -V

-bash-3.2$ /usr/libexec/java_home  -V
Matching Java Virtual Machines (5):
    13.0.2 (x86_64) "Oracle Corporation" - "Java SE 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
    11.0.7 (x86_64) "Oracle Corporation" - "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
    1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
    1.8.0_221 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home


二. 改启动脚本

1. 指定脚本的jdk路径

  • 从报错提示, 确实需要修改的启动脚本: runserver.sh

  • 使用命令 /usr/libexec/java_home -V 查询当前 mac 已安装的 jdk 路径
-bash-3.2$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
    13.0.2 (x86_64) "Oracle Corporation" - "Java SE 13.0.2" /Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
    11.0.7 (x86_64) "Oracle Corporation" - "Java SE 11.0.7" /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home
    1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_301 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
    1.8.0_221 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

我选择的版本是1.8
路径是: /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

  • 使用命令 vim {$path}/runserver.sh ({$path} 表示脚本所在的目录/路径 )

  • 参考下面代码, 将 export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home 添加到启动脚本里
#===========================================================================================
# Java Environment Setting
#===========================================================================================
error_exit ()
{
    echo "ERROR: $1 !!"
    exit 1
}

[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"

# force set java_home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
# force set java_home

export JAVA="$JAVA_HOME/bin/java"
export BASE_DIR=$(dirname $0)/..
export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
  • 保存并退出 :wq , 重启 RocketMQ 即可




参考来源

naco mac 启动报错 /Library/Internet: No such file or directory

在Mac中如何正确地设置JAVA_HOME

posted @ 2021-09-15 14:15  Vitoboy  阅读(767)  评论(1编辑  收藏  举报