It's important to remember that in the first Barbary war, it was Tripoli (one of the Barbary states) that declared war on the US and not the other way around.
Jefferson was elected US president, and because of his intense disdain for the Barbary corsairs and their demanding of tribute to allow safe passage of ships, he refused to continue giving more and more money to the Barbary States. Jefferson found this possible to do because of how weakened the Barbary corsairs were by this point in time.
The second war was declared by the US under Madison, right after the War of 1812 ended, because of the Barbary States attempt to raise tribute prices and continue attacking US shipping.
As to why the European powers never took the initiative in attacking the Barbary States, what /u/SCDareDaemon summed up is 100% correct. Most of the European states found it more effort than it was worth to do anything about the corsairs, or had other reasons to not intervene.