news 2026/4/18 8:20:48

如何升级Bash

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
如何升级Bash

本文描述如何将Bash版本从5.1.8升级到最新的5.3。

💡 Bash 5.1.8 是系统默认安装版本,可以理解为是稳定和成熟的版本。本文只探讨升级过程,对于生产环境,不建议升级。

我的Linux环境为Oracle Linux 9.7, Bash版本5.1.8:

$echo$MACHTYPEx86_64-redhat-linux-gnu $cat/etc/redhat-release Red Hat Enterprise Linux release9.7(Plow)$bash--version GNU bash, version5.1.8(1)-release(x86_64-redhat-linux-gnu)Copyright(C)2020Free Software Foundation, Inc. License GPLv3+: GNU GPL version3or later<http://gnu.org/licenses/gpl.html>This isfreesoftware;you arefreeto change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

从安装包中查看当前Bash的版本信息:

$ yum list installed|grepbashbash.x86_645.1.8-9.el9 @System $ yum infobashLast metadata expiration check:0:01:51 ago on Fri16Jan202606:48:42 AM UTC. Installed Packages Name:bashVersion:5.1.8 Release:9.el9 Architecture:x86_64 Size:7.4M Source:bash-5.1.8-9.el9.src.rpm Repository:@System Summary:The GNU Bourne Again shell URL:https://www.gnu.org/software/bash License:GPLv3+ Description:The GNU Bourne Again shell(Bash)is a shell orcommandlanguage:interpreter that is compatible with the Bourne shell(sh). Bash:incorporates useful features from the Korn shell(ksh)and the C shell:(csh). Mostshscripts can be run bybashwithout modification. Available Packages Name:bashVersion:5.1.8 Release:9.el9 Architecture:src Size:10M Source:None Repository:ol9_baseos_latest Summary:The GNU Bourne Again shell URL:https://www.gnu.org/software/bash License:GPLv3+ Description:The GNU Bourne Again shell(Bash)is a shell orcommandlanguage:interpreter that is compatible with the Bourne shell(sh). Bash:incorporates useful features from the Korn shell(ksh)and the C shell:(csh). Mostshscripts can be run bybashwithout modification.

试图自动升级:

$ sudo yum update bash Last metadata expiration check: 0:35:33 ago on Fri 16 Jan 2026 06:15:31 AM UTC. Dependencies resolved. Nothing to do. Complete!

以上输出表示,基于已配置的官方repository,此bash已是最新版。

实际上5.1这个小版本中,最新的是5.1.16。系统认为5.1.8是最新,应该是处于稳定性的考虑。因为Bash是核心组件,官方通常不会通过 yum update 将其进行升级,最多只会推送同一个小版本系列的安全补丁。

由于不能自动升级,只能下载源码手工安装了。以下安装过程参考 GNU Bash手册 10.1 Basic Installation。

目前Bash版本最新为5.3。首先从GNU官网下载Bash源码:

$wgethttps://ftp.gnu.org/gnu/bash/bash-5.3.tar.gz $ls-lh --time-style=long-iso total 11M -rw-r--r--.1root root 11M2025-07-3014:07 bash-5.3.tar.gz

可以看到源码的日期为25年7月30日,大小11M。

解压,展开后近40M:

$tar-zxf bash-5.3.tar.gz $lsbash-5.3 bash-5.3.tar.gz $du-sh bash-5.3 39M bash-5.3

然后进入标准的安装过程,中间的大量输出省略:

$cdbash-5.3/# configure 耗时 38秒$ ./coechnfigure# make 耗时1分12秒$make# tests耗时2分10秒,报了很多警告,但$?仍是0$maketests# install 耗时12秒$makeinstall

整个过程不到5分钟,还是挺快的。没想到最慢的是下载源码。

💡 默认安装目录为 /usr/local/lib/bash,不会覆盖系统的 /bin/bash。

查看安装的版本:

$ /usr/local/bin/bash --version GNU bash, version5.3.0(1)-release(x86_64-pc-linux-gnu)Copyright(C)2025Free Software Foundation, Inc. License GPLv3+: GNU GPL version3or later<http://gnu.org/licenses/gpl.html>This isfreesoftware;you arefreeto change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

重新登录终端,发现默认的路径已经指向新版本bash:

$whichbash/usr/local/bin/bash $bash--version GNU bash, version5.3.0(1)-release(x86_64-pc-linux-gnu)...

其实是因为PATH中,/usr/local/bin在/usr/bin之前(如果不是,就自己改一下):

$echo$PATH/home/vagrant/.local/bin:/home/vagrant/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin $ls-lh --time-style=long-iso /usr/bin/bash -rwxr-xr-x.1root root1.4M2024-05-01 05:59 /usr/bin/bash $ls-lh --time-style=long-iso /usr/local/bin/bash -rwxr-xr-x.1root root4.4M2026-01-16 07:26 /usr/local/bin/bash

但是man page还是老版本的:

$man-Pcatbash|tail-1 GNU Bash5.12020October29BASH(1)$find/ -name bash.1.gz /usr/share/man/man1/bash.1.gz

就下来就有两种方式供选择,一个是新老Bash共存,一个是只想用新版本。

稳妥起见,建议新老版本共存。此时可以用符号链接和别名方式。

例如:

# cd /usr/bin# ls -l bash*-rwxr-xr-x.1root root1389064May12024bash# ln -s /usr/local/bin/bash bash52# ls -l bash*-rwxr-xr-x.1root root1389064May12024bashlrwxrwxrwx.1root root19Jan1608:25 bash52 ->/usr/local/bin/bash# bash52# echo $BASH_VERSION5.3.0(1)-release# echo $MANPATH/usr/share/man:# alias man52="MANPATH=/usr/local/share/man man"# man52 -P cat bash| tail -1GNU Bash5.32025April7BASH(1)

如果想用新版本彻底替代老版本,以下是一些标准的方法:

sudobash-c'echo /usr/local/bin/bash >> /etc/shells'chsh -s /usr/local/bin/bash

我并没有执行,因为chsh还未安装。

不过以下给出了一种方式,例如只让某个用户(例如vagrant)使用最新的Bash:

# usermod -s /usr/local/bin/bash vagrant# grep vagrant /etc/passwdvagrant:x:1000:1000::/home/vagrant:/usr/local/bin/bash

其实就是把用户的login shell改了。用putty试了一下,可以的:

Using username"vagrant".Authenticating with public key"vagrant"Welcome to Oracle Linux Server release9.5(GNU/Linux5.15.0-206.153.7.el8uek.x86_64)The Oracle Linux End-User License Agreement can be viewed here: * /usr/share/eula/eula.en_US For additional packages, updates, documentation and community help, see: * https://yum.oracle.com/ Last login: Fri Jan1607:57:302026from10.0.2.2[vagrant@ol9-vagrant ~]$echo$VERSION_INFO[vagrant@ol9-vagrant ~]$echo$BASH_VERSION5.3.0(1)-release
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/18 3:38:02

零基础排查ESP-IDF路径错误:完整解决方案详解

零基础也能搞定&#xff01;ESP-IDF 路径报错全解析&#xff1a;从“找不到 idf.py”到环境正常运行你是不是也遇到过这种情况——刚装好 ESP-IDF&#xff0c;信心满满打开终端准备idf.py build&#xff0c;结果弹出一行红字&#xff1a;the path for esp-idf is not valid或者…

作者头像 李华
网站建设 2026/4/17 21:55:01

SGLang DSL语言入门:复杂逻辑编程部署实战

SGLang DSL语言入门&#xff1a;复杂逻辑编程部署实战 1. 引言 随着大语言模型&#xff08;LLM&#xff09;在各类应用场景中的广泛落地&#xff0c;如何高效、稳定地部署这些模型成为工程实践中的关键挑战。传统的推理方式往往面临吞吐量低、延迟高、资源利用率不足等问题&a…

作者头像 李华
网站建设 2026/4/17 8:06:11

8B参数够强吗?Qwen3-VL多场景验证

8B参数够强吗&#xff1f;Qwen3-VL多场景验证 1. 引言&#xff1a;小模型也能扛大任&#xff1f; 在当前大模型“参数军备竞赛”愈演愈烈的背景下&#xff0c;动辄百亿、千亿参数的视觉-语言模型&#xff08;VLM&#xff09;虽然能力强大&#xff0c;却严重依赖高端算力&…

作者头像 李华
网站建设 2026/4/18 2:15:37

Qwen3-4B-Instruct资源优化:4090D下高效运行参数详解

Qwen3-4B-Instruct资源优化&#xff1a;4090D下高效运行参数详解 1. 简介 Qwen3-4B-Instruct-2507 是阿里云推出的一款开源轻量级大语言模型&#xff0c;专为高效率、高质量文本生成任务设计。该模型在通用能力方面实现了显著提升&#xff0c;涵盖指令遵循、逻辑推理、文本理…

作者头像 李华
网站建设 2026/4/18 3:27:41

快速理解L298N电机驱动原理图与Arduino协同工作

深入剖析L298N电机驱动&#xff1a;从原理图到Arduino实战控制你有没有遇到过这样的情况&#xff1f;接好了线&#xff0c;代码也烧录进去了&#xff0c;可电机就是不转&#xff1b;或者刚启动就发热严重&#xff0c;甚至Arduino莫名其妙重启。如果你正在用L298N驱动直流电机&a…

作者头像 李华
网站建设 2026/4/18 3:29:16

IQuest-Coder-V1部署报错?显存优化步骤详解一文搞定

IQuest-Coder-V1部署报错&#xff1f;显存优化步骤详解一文搞定 1. 引言&#xff1a;IQuest-Coder-V1-40B-Instruct 的定位与挑战 IQuest-Coder-V1-40B-Instruct 是面向软件工程和竞技编程的新一代代码大语言模型&#xff0c;属于 IQuest-Coder-V1 系列中的指令优化变体。该系…

作者头像 李华