And a ruler asked him, "Good Teacher, what must I do to inherit eternal life?" And Jesus said to him, ''Why do you call me good? No one is good except God alone. You know the commandments: Do not commit adultery, Do not murder, Do not steal, Do not bear false witness, Honor your father and mother." And he said, "All these I have kept from my youth." When Jesus heard this, he said to him, "One thing you still lack. Sell all that you have and distribute to the poor, and you will have treasure in heaven; and come, follow me." But when he heard these things, he became very sad, for he was extremely rich. Luke 18:18-23
Is Jesus saying that we can earn eternal life by giving everything to the poor? Not exactly. Jesus was trying to show this man that he had not in fact kept all the commandments. The ruler sinned by breaking the first commandment, You shall have no other gods before me (Exodus 20:3). When exposed, the ruler left disheartened rather than seeking forgiveness. Only when you recognize that you cannot be good enough to inherit eternal life are you ready to accept the gift of eternal life.
What is this gift of salvation? You broke God's law (we all did); Jesus, God in the flesh, paid the fine! He died in the place of guilty sinners, was buried, and rose again. You must ask God for mercy, trusting in Jesus and turning from your sin. Once you do this, you'll become a new person who now desires to do God's will. You can find God's will by reading the Bible and praying to God for insight!
Additional References: Romans 3:21-26, 5:6-11, 6:23, 10:9-13