解决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 文件后,重新打开一个新的终端会话即可。

相关推荐
zhaqonianzhu6 分钟前
Linux GPIO 使用 Pinctrl 及 Gpiolib 通俗详解
linux·安卓
网硕互联的小客服16 分钟前
408 Request Timeout:请求超时,服务器等待客户端发送请求的时间过长。
运维·服务器
王伯安呢18 分钟前
告别线缆束缚!AirDroid Cast 多端投屏,让分享更自由
运维·服务器·教程·投屏·airdroid cast·多端互投
逍遥浪子~22 分钟前
搭建本地gitea服务器
运维·服务器·gitea
骄傲的心别枯萎25 分钟前
RV1126 NO.16:通过多线程同时获取H264和H265码流
linux·c++·音视频·rv1126
空灵之海26 分钟前
Ubuntu系统安全合规配置
linux·ubuntu·系统安全·1024程序员节
喜欢你,还有大家30 分钟前
FTP文件传输服务
linux·运维·服务器·前端
Bi1 小时前
Dokploy安装和部署项目流程
运维·前端
czhc11400756631 小时前
LINUX99 centos8:网络 yum配置;shell:while [ $i -ne 5 ];do let i++ done
linux
霍格沃兹软件测试开发1 小时前
AI 测试平台新功能揭秘:自动化测试用例运行的奥秘
运维·自动化·测试用例