There was a man who once asked Jesus, "Teacher, what shall I do to inherit eternal life?" (Luke 10:25).
The correct answer is:
You shall love the Lord your God with all your heart and with all your soul and with all your strength and with all your mind, and your neighbor as yourself. (Luke 10:27)
So, how do you get eternal life? Love God and love others.
The Bad News
However, there's a problem. It turns out that no one has ever been able to love God and love others perfectly. Loving God and loving others involves obeying all God's commandments, because God commands what he is: love!
Those commandments include things like not worshipping anything or anyone other than God (Exodus 20:3-4), not murdering (Exodus 20:13), not stealing (Exodus 20:15), and not committing adultery (i.e., not having sex with someone who's not your spouse) (Exodus 20:14).
Have you ever done these things? Maybe you consider yourself to be a 'good person' since you can't remember ever committing one of these sins.
But have you ever disrespected your parents (Exodus 20:12)? Lied (Exodus 20:16)? Coveted something that wasn't yours (Exodus 20:17)? How about lusted over a pretty woman or a handsome guy (Matthew 5:27-28)? Been unjustifiably angry with someone or insulted someone (Matthew 5:21-22)?
I'm certain that each of us have done all of these sins at some point in our lives, even if only in our hearts.
Unfortunately, breaking even one of these commandments is the same as breaking all of them (James 2:10). Even worse, God says that the proper punishment for any sin is eternal death. Because God is perfectly loving, and sin is the opposite of love, then God must punish sin.
That means we're all in very serious trouble, since everyone has sinned (Romans 3:23), and so everyone deserves eternal death (Romans 6:23).
That's the bad news, and if you're feeling guilty right now, that's actually a good thing. We need to hear the bad news before we can understand and believe the good news (a.k.a. the gospel).
It's like when you go to a doctor because you're not feeling well, and the doctor has to first diagnose your problem before proper treatment can begin. Humanity is afflicted with a terminal disease called 'sin', and it'll catch up with each of us sooner or later.
But there's also some very good news.
The Good News
Look at Romans 6:23 again:
For the wages of sin is death, but the free gift of God is eternal life in Christ Jesus our Lord.
Perhaps the most famous verse in the Bible is:
For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life. (John 3:16)
That's the good news. God loves us so much that he doesn't want to have to sentence us to the punishment of eternal death that we all deserve. So God created a solution which upholds both God's justice and God's love for all people.
The solution was for God to send his Son into the world to become a human being, who was Jesus of Nazareth, also known as Jesus the Messiah, or Jesus Christ.
But because Jesus was both fully human and fully divine, Jesus never sinned. This means Jesus was able to die on behalf of every single person and take the divine punishment that we deserved:
For God made Christ, who never sinned, to be the offering for our sin, so that we could be made right with God through Christ. (2 Corinthians 5:21, NLT)
But since Jesus is God, God was effectively absorbing God's own punishment that we deserve for our sins by transferring our guilt to Jesus. When Jesus died on the cross, he experienced all God's wrath and anger that our sins deserve. Just read Isaiah 53.
The Bible tells us that,
God shows his love for us in that while we were still sinners, Christ died for us. Since, therefore, we have now been justified by his blood, much more shall we be saved by him from the wrath of God. (Romans 5:8-9)
Thus, there's no longer any punishment left for us (Romans 8:1) because Jesus' blood that he shed on the cross allows God to justly forgive our sins (Acts 10:43, Hebrews 9:22, 9:11-14). Now we can receive God's free gift of eternal life, provided that we simply believe that Jesus did in fact die for our sins so that we can have eternal life.
Here's a selection of verses that support this claim:
Truly, truly, I say to you, whoever hears my word and believes him who sent me has eternal life. He does not come into judgment, but has passed from death to life. (John 5:24)
Whoever believes in the Son has eternal life; whoever does not obey the Son shall not see life, but the wrath of God remains on him. (John 3:36)
For God did not send his Son into the world to condemn the world, but in order that the world might be saved through him. Whoever believes in him is not condemned, but whoever does not believe is condemned already, because he has not believed in the name of the only Son of God. (John 3:17-18)
As confirmation of all of this, God raised Jesus from the dead, as proof that one day, everyone who believed in Jesus will also be resurrected (1 Corinthians 15:20-22), and we will be given perfect new bodies that will never get sick, age, or die (1 Corinthians 15:51-53).
Jesus promised,
For this is the will of my Father, that everyone who looks on the Son and believes in him should have eternal life, and I will raise him up on the last day. (John 6:40)
Then we'll live forever with God on a perfect New Earth, where there won't be any more suffering or death (Revelation 21:3-4).
Summary
So the simplest answer (and ultimately, the only answer) to the question "how can I have eternal life?" is "believe in Jesus". There's nothing else you need to do.
There are three clear Biblical examples that confirm this.
When Jesus was teaching a crowd, some people asked him "What must we do, to be doing the works of God?" Jesus answered them, "This is the work of God, that you believe in him whom he has sent." (John 6:28-29)
When Jesus was dying on the cross, there was a criminal who was dying next to him. The criminal admitted that he deserved his punishment for his crimes, but he knew that Jesus was innocent. He trusted that Jesus would one day have a kingdom just like Jesus had said, and the criminal asked to be remembered by Jesus. Jesus promised him that after the criminal died he would be in paradise with Jesus (Luke 23:39-43).
When two Christians had just been freed from jail by God through a miracle, the stunned and likely terrified jailor asked them "Sirs, what must I do to be saved?" And they said, "Believe in the Lord Jesus, and you will be saved, you and your household." (Acts 16:30-31)
So that's it. Do you believe this is true? If you answered yes to that question, then congratulations, you've now got eternal life!
Even better, you will never lose this eternal life. Jesus said,
My sheep hear my voice, and I know them, and they follow me. I give them eternal life, and they will never perish, and no one will snatch them out of my hand. (John 10:27-28)
Elsewhere, we're told that,
neither death nor life, nor angels nor rulers, nor things present nor things to come, nor powers, nor height nor depth, nor anything else in all creation, will be able to separate us from the love of God in Christ Jesus our Lord. (Romans 8:38-39)
This is because,
In him you also, when you heard the word of truth, the gospel of your salvation, and believed in him, were sealed with the promised Holy Spirit, who is the guarantee of our inheritance until we acquire possession of it, to the praise of his glory. (Ephesians 1:13-14)
This free gift is available to everyone who believes, because God wants to save everyone (1 Timothy 2:3-4, 2 Peter 3:9). So if you have friends or family who haven't heard about this offer you can tell them about it.
What Should I Do Now?
If you have just believed in Jesus as your savior, you might be wondering what it means to be a Christian, and what you should do now. Here's my recommendations:
Pray and thank God for loving you so much that he sent Jesus to die for your sins. Through prayer, you can have a personal relationship with Jesus/God. Take time each day to pray to him about your day, your worries, things you're thankful for, and ask him to help you and guide your decisions.
Consider being baptized and celebrating the Lord's Supper/Communion/Eucharist with a group of faithful Christians. By attending a Christian church regularly, you'll gain a community of like-minded people who you can worship with, and who can encourage you and help you grow in your faith. You also have spiritual gifts you can use to help others.
Take some time each day to read the Bible, since it's God's inerrant word to us. Find a translation you like. I'd recommend the ESV, NRSV, NKJV, NASB, NLT, or CEV, but others work also as long as they're not the Jehovah's Witness version (New World Translation) which isn't trustworthy. I'd also avoid The Message, since it's only a paraphrase of the Bible. A "study Bible" version of one of the above recommended translations might be a good choice because study Bibles have lots of extra details in the footnotes that can help explain things. Attending a Bible study with other Christians can also help you learn more and provides a generally safe place to ask questions.
Pursue sanctification by doing good works to earn heavenly rewards and asking God to help you learn to overcome sin in your life. If there's any sin the Holy Spirit is convicting you of in particular, work on giving that up, and go ask for forgiveness from whoever you might have sinned against. Looking forward to heaven is also helpful to give motivation to pursue sanctification. But don't worry, there's no such thing as purgatory and so you don't need to become perfectly holy in this life, although avoiding sin is certainly beneficial to avoid suffering, because all sin causes suffering.
Read some theology to learn more about God and Jesus, such as some of the other posts here on my blog and Christian books like the ones I've recommended here. But remember, just because an expert says something doesn't make it true, so reading theology requires discernment which is gained through studying the Bible and praying for the Holy Spirit to lead you to the truth (John 16:13). It also helps to be open to changing your mind on non-essential theological issues, and remembering that correct theology isn't necessary for eternal salvation. Neither are good works, by the way.
Look forward to the Rapture! It's going to be great, and it could happen literally anytime now. On the other hand, if you've become a Christian after the Rapture has already occurred, then it is important for you to read my posts about how to identify the Antichrist and why you absolutely must not take the upcoming Mark of the Beast.
Conclusion
Again, if you just accepted Jesus' offer by putting your faith in him, then congratulations on gaining eternal life and starting your journey as a Christian. Your life might still be tough, since Jesus promises us that in this life we'll always face difficulties (John 16:33).
We might even be persecuted for our faith!
Jesus said,
If the world hates you, know that it has hated me before it hated you. If you were of the world, the world would love you as its own; but because you are not of the world, but I chose you out of the world, therefore the world hates you. Remember the word that I said to you: "A servant is not greater than his master." If they persecuted me, they will also persecute you. (John 15:18-20)
This will become increasingly true because the world is rapidly approaching the prophesied end-times. But the eternity we're promised in heaven infinitely outweighs everything else, and makes all our suffering here infinitely small in comparison:
For this light momentary affliction is preparing for us an eternal weight of glory beyond all comparison, as we look not to the things that are seen but to the things that are unseen. For the things that are seen are transient, but the things that are unseen are eternal. (2 Corinthians 4:17-18)
Let's do our best to live for eternity in the short time we each have left.