I'd like to expand on what g1smd said. It's true that the "no-www" to "with-www" 301 redirect will handle that common canonical problem. However, there are many other potential canonical URL issues that, though less common, can still wreak havoc if they come up.
For that reason I prefer to use the canonical element in addition to doing everything possible on the server itself. For a really thorough guide to handling things servers-side, see this thread: A guide to fixing duplicate content & URL issues on Apache [webmasterworld.com]