LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-30-2009, 10:35 PM   #1
Andrew Dufresne
LQ Newbie
 
Registered: Sep 2009
Distribution: Fedroa 10
Posts: 27

Rep: Reputation: 16
How to use different versions of grep on same system?


Hi,

I have got two versions of grep on my system.

grep 2.5.1 which is in /bin
grep 2.5.4 which is in /usr/local/bin . I complied it from source code.

Question 1
Now, 'yum info grep' still shows the older 2.5.1a version. How can I tell yum that a new version of grep in on board now?

Question 2
How can I remove the old grep? I tried using 'yum remove grep' but then it showed a huge list that too will be removed with grep so I didn't pursue this way. What will be the proper way?

Question 3
When I run grep as a root, it uses 2.5.4. Although /bin and /usr/local/bin both are in root's $PATH.
But when I run grep as user, it uses 2.5.1. Here too /bin and /usr/local/bin both are in its $PATH.

What is the reason of this different behaviour?

How can I ensure that every user gets grep 2.5.4 without using its absolute path?

Regards
 
Old 09-30-2009, 11:20 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: SlackWare > Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie stretch buster
Posts: 1,621

Rep: Reputation: 98
Hya!

Answer 1. use absolute path.

Answer 2. may not be easy.

Answer 3. The one found first will kick in. Check PATH variable and which one comes first. (/bin and /usr/local/bin)

Happy Penguins!
 
Old 09-30-2009, 11:32 PM   #3
Andrew Dufresne
LQ Newbie
 
Registered: Sep 2009
Distribution: Fedroa 10
Posts: 27

Original Poster
Rep: Reputation: 16
Thanks for the reply.

Quote:
Originally Posted by kaz2100 View Post
Answer 3. The one found first will kick in. Check PATH variable and which one comes first. (/bin and /usr/local/bin)
Well in both cases; root and user, /usr/local/bin comes first. But still user uses /bin version unlike root

Here is the $PATH of root

Quote:
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
and here is the $PATH of user

Quote:
$ echo $PATH
/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/Andy/bin

Quote:
Originally Posted by kaz2100 View Post
Quote:
Originally Posted by Andrew Dufresne View Post
Hi,
Question 1
Now, 'yum info grep' still shows the older 2.5.1a version. How can I tell yum that a new version of grep in on board now?
Answer 1. use absolute path.
I tried
Code:
yum info /usr/local/bin/grep
But it gave me, "Error : No matching Packages to list".

So what do you suggest now?
 
Old 10-01-2009, 12:26 AM   #4
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
change the $PATH variable and make /bin come before the /usr/local/bin
 
Old 10-01-2009, 12:50 AM   #5
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos
Posts: 267

Rep: Reputation: 54
Q1: don't know

Q2: mv /bin/grep /bin/grep.old

Q3; ln -s /usr/local/bin/grep /bin/grep (after you have done Q2 above. Make sure it is has permissions as the original grep had. (usually -rwxr-xr-x. 1 root root 89964 2009-02-25 11:04 /bin/grep)
 
1 members found this post helpful.
Old 10-01-2009, 01:07 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
You've had some good answers for q2, q3.
Re q1; you can't; yum only recognises stuff installed via yum (actually rpm under the covers).
See rpm -V
 
Old 10-01-2009, 01:12 AM   #7
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 335

Rep: Reputation: 141Reputation: 141
Your user shell may have hashed the location of the old grep command and this could be why it doesn't find the new version.
'hash' is a bash builtin command. As the shell finds commands along the search path it remembers the found location in an internal hash table. The next time you enter a command the shell uses the value in its hash table instead of searching the path again.
Code:
# To see your 'hash' table:-
hash

# If 'grep' is on the hash table you can delete it with:-
hash -d grep
 
Old 10-01-2009, 01:27 AM   #8
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by Andrew Dufresne View Post
Hi,

I have got two versions of grep on my system.

grep 2.5.1 which is in /bin
grep 2.5.4 which is in /usr/local/bin . I complied it from source code.

Question 1
Now, 'yum info grep' still shows the older 2.5.1a version. How can I tell yum that a new version of grep in on board now?

Question 2
How can I remove the old grep? I tried using 'yum remove grep' but then it showed a huge list that too will be removed with grep so I didn't pursue this way. What will be the proper way?

Question 3
When I run grep as a root, it uses 2.5.4. Although /bin and /usr/local/bin both are in root's $PATH.
But when I run grep as user, it uses 2.5.1. Here too /bin and /usr/local/bin both are in its $PATH.

What is the reason of this different behaviour?

How can I ensure that every user gets grep 2.5.4 without using its absolute path?

Regards
The solution is to make a shortcut in /usr/local/bin to the grep version you want to use. Typically, /usr/local/bin is searched first in a path search, so this location get priority.

1. Move the grep version located in /usr/local/bin somewhere else.

2. symlink from /usr/local/bin to the desired version.

Quote:
grep 2.5.4 which is in /usr/local/bin . I complied it from source code.
Can I ask you something? Why did you do do that? What was wrong with the provided grep version? Are you aware that you could have compiled it so it overwrote the version in /bin? And that you can still move the copy in /usr/local/bin to /bin?
 
Old 10-01-2009, 01:34 PM   #9
Andrew Dufresne
LQ Newbie
 
Registered: Sep 2009
Distribution: Fedroa 10
Posts: 27

Original Poster
Rep: Reputation: 16
Thanks to all you guys for replying to my queries so promptly.

Quote:
Originally Posted by Andrew Dufresne View Post
Question 1
Now, 'yum info grep' still shows the older 2.5.1a version. How can I tell yum that a new version of grep in on board now?
Quote:
Originally Posted by chrism01 View Post
Re q1; you can't; yum only recognises stuff installed via yum (actually rpm under the covers).
See rpm -V
Oh I didn't know that. Thanks for clearing that up to me.

Quote:
Originally Posted by Andrew Dufresne View Post
Question 2
How can I remove the old grep? I tried using 'yum remove grep' but then it showed a huge list that too will be removed with grep so I didn't pursue this way. What will be the proper way?
Surely I can rename the old version into grep.old as suggested by ArfaSmif. Actually I asked this question to learn something new. I mean I have always observed that to remove a package I just have to "yum remove package" but in this case the programs getting affected with grep removal were so many that I stopped right there.

Now, it seems that is really not easy to remove grep. No big deal, I can live with that. But if somebody as any idea about it then please share.

Quote:
Originally Posted by Andrew Dufresne View Post
Question 3
When I run grep as a root, it uses 2.5.4. Although /bin and /usr/local/bin both are in root's $PATH. But when I run grep as user, it uses 2.5.1. Here too /bin and /usr/local/bin both are in its $PATH. What is the reason of this different behaviour? How can I ensure that every user gets grep 2.5.4 without using its absolute path?
Quote:
Originally Posted by Kenhelm View Post
Your user shell may have hashed the location of the old grep command and this could be why it doesn't find the new version.
'hash' is a bash builtin command. As the shell finds commands along the search path it remembers the found location in an internal hash table. The next time you enter a command the shell uses the value in its hash table instead of searching the path again.
Code:
# To see your 'hash' table:-
hash

# If 'grep' is on the hash table you can delete it with:-
hash -d grep
Thanks a lot Kenhelm. It solved my problem. This is what I love about Linux, you learn something new almost everyday.
 
Old 10-01-2009, 01:45 PM   #10
Andrew Dufresne
LQ Newbie
 
Registered: Sep 2009
Distribution: Fedroa 10
Posts: 27

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by lutusp View Post
The solution is to make a shortcut in /usr/local/bin to the grep version you want to use. Typically, /usr/local/bin is searched first in a path search, so this location get priority.

1. Move the grep version located in /usr/local/bin somewhere else.

2. symlink from /usr/local/bin to the desired version.
Thanks for your suggestions.

Quote:
Originally Posted by lutusp View Post
Can I ask you something? Why did you do do that? What was wrong with the provided grep version? Are you aware that you could have compiled it so it overwrote the version in /bin? And that you can still move the copy in /usr/local/bin to /bin?
Actually grep 2.5.1 seems to have a bug in it. Please see this thread for details.

Quote:
Originally Posted by lutusp View Post
Are you aware that you could have compiled it so it overwrote the version in /bin?
Really? How? Please enlighten me in this regard.

The INSTALL help with source code says
Code:
./configure;  make ; make check ; make install
so I did it. Which command should I add here to overwrite the previous version?

Moreover, old version of grep was installed with yum, so I don't think a compilation can affect previous version in anyway. If you have any idea then please share?

Quote:
Originally Posted by lutusp View Post
And that you can still move the copy in /usr/local/bin to /bin?
Sure I can. But I try my best to avoid issuing any command as root or changing environmental variables. That's why I was looking for other ways.

Regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to have two different versions of GCC in the same system ?? nasty_daemon Linux - Software 2 09-07-2005 10:49 AM
can't grep in the RH system ust Linux - Software 5 05-24-2005 07:27 AM
May 2 versions of the same rpms existing in just 1 Linux system? jiapei100 Linux - General 3 03-12-2005 05:16 PM
Two glibc versions, one system: Possible? ellakano Linux - Software 3 09-05-2004 03:28 PM
Can you have two different versions of gcc on the same system? the theorist Linux - Software 1 02-23-2004 04:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration