There was another tree in the garden, a tree which sat in the middle of the garden alongside the tree of the knowledge of good and evil. That tree was the tree of life. God did not tell Adam that he could not eat of the fruit of that tree. But, when the fall occurred, God cast Adam and Eve from the garden so that they could not eat from the tree of life. Why? Genesis 3:22 tells us that it's because, if they ate of the fruit of that tree, they would live forever. Because God is righteous and just, He removed them from the garden. Sin and disobedience could not be allowed to exist along with eternal life.
But God's plan was always for man to have eternal life. He is righteous and just, but He is also a merciful and loving God. So, God made a way for man to once again have eternal life in His presence. He gave His only Son, Jesus Christ, to pay the price for man's sin. Eternal life was restored through the sacrifice of Jesus, who died so that we all could have eternal life. This is a gift from God. There is nothing we can do to earn it. All we need to do is believe in Jesus, believe that He is our Savior, give our lives to Him, and turn from our sin. When we do, we are declared righteous and, although we will one day leave these earthly bodies, we will have eternal life with Him in heaven.