更新Bash路径的缓存
2024-10-21 06:44:27
---恢复内容开始---
1、登陆一个新的vps时候,发现git的版本是1.8的,太久了,于是就源码安装了新的版本2.4。
2、老版本在/usr/bin/git,新版本安装的/usr/local/bin/git
3、问题来了,安装完新的后,卸载了旧的版本,在运行git --version时,却提示如下错误:
-bash: /usr/bin/git: No such file or directory
4、我去,bash只搜索旧的路径,查看了一下PATH变量:
[root@noi bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
没有问题,而且/usr/local/bin还在前面,但系统却不搜索,我晕,这是啥问题?
5、经过一番折腾,终于找到答案,原来Bash路径也是有缓存地,只要运行过的命令,bash就会保存到一张hash表里,下次直接从hash表里找地址,就不按个路径找了。
6、运行:help hash查看一下:
[root@noi bin]# help hash
hash: hash [-lr] [-p pathname] [-dt] [name ...]
Remember or display program locations. Determine and remember the full pathname of each command NAME. If
no arguments are given, information about remembered commands is displayed. Options:
-d forget the remembered location of each NAME
-l display in a format that may be reused as input
-p pathname use PATHNAME is the full pathname of NAME
-r forget all remembered locations
-t print the remembered location of each NAME, preceding
each location with the corresponding NAME if multiple
NAMEs are given
Arguments:
NAME Each NAME is searched for in $PATH and added to the list
of remembered commands. Exit Status:
Returns success unless NAME is not found or an invalid option is given.
7、在运行hash命令,查看hash表里都有啥?
[root@noi bin]# hash
hits command
/usr/bin/git
/usr/sbin/ifconfig
/usr/bin/rm
/usr/bin/vim
/usr/bin/wget
/usr/bin/mv
/usr/bin/yum
/usr/bin/ln
/usr/bin/man
/usr/bin/make
/usr/bin/tar
/usr/bin/ls
果然,第一个就是git,而且地址还是老地址。
8、运行: hash -d git 删除掉git的缓存。
9、再次执行git --version 哈哈,正确显示了新安装的版本。
---恢复内容结束---
最新文章
- pxe无人值守安装多网卡注意事项
- Mongodb的备份,恢复,导入与导出(cmd命令行实现)
- sql-将一个表中的数导入另一个表中
- php微信接口实例
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest, B. Layer Cake
- StackTrace,Trim
- Netdom query基本用法
- YII 快速创建项目GII
- Windows Phone使用sliverlight toolkit实现页面切换动画效果
- 基于lua的网页脚本开发语言cgilua(转)
- 安卓组件-BroadcastReceiver
- 为什么ABAP开发者需要使用面向对象技术?
- 【TensorFlow 官网 可以直接访问】让中国开发者更容易地使用TensorFlow打造人工智能应用
- Python 实现 KD-Tree 最近邻算法
- [OC] NSTimer
- grafana--邮箱告警配置
- [LeetCode] Number of Matching Subsequences 匹配的子序列的个数
- SaltStack安装配置详解
- 学习笔记11—MATLAB 界面设计
- SpringMVC参考
热门文章
- <;摘录>;cocos2d-x 从环境搭建到win32项目移植android平台
- PatchGuard Disabled V3
- Visio显示不完整
- 在matlab中clear,clc,clf,hold作用介绍
- 表单对象属性disabled和readOnly
- c++类模板template中的typename使用方法-超级棒
- (转)HBase 常用Shell命令
- libev客户端
- MySQL : ERROR 1042 (HY000): Can&#39;t get hostname for your address
- leetcode 282. 给表达式添加运算符