Do you have to un-install the previous version or does the 4.0 installer take care of everything?
I would recommand to uninstall first. Your settings are still kept (at least the win uninstaller will keep them, unless you chose otherwise / checkbox).
Though in many cases, if you do not uninstall it works when you do a "clean rebuild" after install (a rebuild is needed anyway, if you have packages installed).
If you are on Linux/Mac you can keep the FPC and FPC-source parts, since they have not changed (unless you skipped several versions of Lazarus).
On Windows instead of an uninstall, you can remove/delete all files from the installation folders (assuming you have a normal install, and your config therefore is in C:\users).
The only reason why an uninstall/delete may be needed is because sometimes (between version) files have been moved to new location. The installer does not remove the old ones, and when the files suddenly are in 2 locations, then that can cause problems.
To find the location of your config (if you want to back it up)
Menu: View > Ide Internals > About IDE
In the window that opens look for "primary config path".
This is were all your config/settings are. Including which packages are installed.
And usually also any packages that you downloaded with the online package manager.
About packages.
When you start the new IDE first time, it may give some warnings. Your installed packages will not be active. But the IDE still knows them.
Menu: Tools > Build Lazarus using profile ....
That will restore them.
Mind that 3rd party package (online package manager) may need to be upgraded to work. If not the compilation may give errors, or the rebuild IDE may not work correct (there will be a "lazarus.exe.old" in that case).
So if you have OPM packages, open the OPM and update them.