解决Linux每次开启新会话不自动执行 ~/.bashrc 的问题

问题原因

系统中缺少 .bash_profile 文件。

解决方案

1. 创建 .bash_profile 文件

使用以下命令创建 .bash_profile 文件:

bash 复制代码
vim ~/.bash_profile

2. 添加脚本内容

将以下脚本内容复制并粘贴到 .bash_profile 文件中:

bash 复制代码
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

重新打开会话

保存并关闭 .bash_profile 文件后,重新打开一个新的终端会话即可。

相关推荐
心易行者29 分钟前
Agent应用+API端点商业化进阶实战:从单体智能体到可付费调用的API全流程
运维·服务器·人工智能·python·apache
科技研学社36 分钟前
精度决胜品质:羽绒服缝制工艺标准与自动化精度对标解析
运维·自动化
夜之眷属42 分钟前
Core dump 崩溃排查:JVM 宕机后,那份 core 文件怎么用 gdb 还原现场
java·运维·服务器·jvm
Initialize2930842 分钟前
Redis 内存打满、连接数飙红?运维排查四步法
运维
zly350044 分钟前
centos7 mount设备挂载 /dev/sda1/硬盘挂载
linux·运维·服务器
零基础1231 小时前
FinalShell 使用教程:从安装到高效运维
运维·经验分享·笔记·finalshell
帷幕落秋1 小时前
Docker的两种安装
运维·docker·容器
工业一体机老司机1 小时前
工业一体机选购后的系统部署:Ubuntu下Docker容器化运行与GPIO配置
linux·ubuntu·docker·人机交互
fengkai45451 小时前
十二、Redis -2
运维·数据库·redis·容器
哎呦,帅小伙哦2 小时前
进程监控工具——htop
linux·运维·服务器