There is no universal answer to this question. Actually, there are a lot of different parasites out there and they all have their own specific characteristics. As such, you can have a parasite only for a few days or it can live inside you for the rest of your life.
Even though exceptions are always possible, when human is infected as an accidental host, meaning that the final host for this specific parasite is an animal rather than human, the parasite is usually not able to cause a persistent infection and clears itself relatively quickly. For example, this is the case of the porcine whipworm Trichuris suis that stays only transiently in the human intestine for about 2 weeks.
Furthermore, in otherwise healthy people, some parasites infecting human as their final host can also go away on their own after a few weeks without any specific treatment. It is notably the case of some mild intestinal diseases caused by either Giardia intestinalis or by one of the coccidian parasites, namely Cyclospora cayetanensis, Cryptosporidium species and Cystoisospora belli.
At the other extremity of the spectrum, there are some parasites, such as Toxoplasma gondii, that remain usually within the body throughout the lifetime. It is estimated than more than half the population of the world is currently living with this parasite. Actually, in the rare occasion where symptoms occur from the infection with Toxoplasma gondii, they are successfully treated but medication cannot kill all parasites present within the body for good. As such, cysts remain present in different part of the body for the person’s lifetime.
Between both extremes, there is a wide range of possibilities depending on the parasites involved. However, it is noteworthy that parasites are usually quite persistent in the human body without proper treatment. For example, some helminths, such as tapeworms, can live up to 25 years into the human gut.
Finally, it is interesting to note that in the case of protozoan parasites that are replicating themselves quickly, individual parasites are not living so long within the body. In fact, they can usually live up to a few days or weeks, but the general population is renewed with the help of the adequate replication process. On the other side, helminths might not be able to replicate themselves while in the mature stage. As such, individual worms can usually live between 1 and 8 years within their host depending of the species involved.
Source: Centers for Disease Control and Prevention