Shane wanted to take Rick’s place
Shane loved Lori and was shocked when Rick returned. He always wanted to take the place of Rick especially after he left.
Rick started distrusting Shane
Rick started becoming uncomfortable around Shane as he no longer trusted him. This resulted in a lot of tension.
Shane tried to kill rick
Shane tried to kill Rick twice. It was clear to Rick that he must get rid of him sooner or later.
Shane became a threat
As Shane’s intentions weren’t that clear Rick realized that Shane became a threat. It was clear that he will have to get rid of him one day. (See Why the Walking Dead is so popular?)
To defend himself
Shane lured Rick away to kill him. Rick pulled his knife in the last moment and did it first. (See Why do people binge-watch TV shows?)