wget gives error "dyld: Library not loaded: /opt/local/lib/libnettle.4.dylib" When I try to use wget, I am getting this error message:

$: wget
dyld: Library not loaded: /opt/local/lib/libnettle.4.dylib
  Referenced from: /opt/local/bin/wget
  Reason: image not found
Trace/BPT trap: 5


I have reinstalled wget using homebrew (brew reinstall wget), I updated and upgraded my homebrew, however this hasn't helped.

In my /opt/local/lib/ folder I cannot find libnettle.4.dylib, however I do find /opt/local/lib/libnettle.6.dylib. I tried to solve the problem by simply symlinking from /opt/local/lib/libnettle.6.dylib to /opt/local/lib/libnettle.4.dylib. This didn't help either, but got me a new error message:

$ wget
dyld: Library not loaded: /opt/local/lib/libhogweed.2.dylib
  Referenced from: /opt/local/lib/libgnutls.28.dylib
  Reason: image not found
Trace/BPT trap: 5


When I run brew info wget, I get this output:

wget: stable 1.17.1 (bottled), HEAD
Internet file retriever
https://www.gnu.org/software/wget/
/usr/local/Cellar/wget/1.17.1 (9 files, 1.6M) *
  Built from source with: --with-debug
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/wget.rb
==&gt; Dependencies
Build: xz ✔, pkg-config ✔
Recommended: openssl ✔
Optional: libressl ✔, pcre ✔, libmetalink ✔, gpgme ✔
==&gt; Options
...


How can I fix this?
I think you have both MacPorts and Homebrew installed. MacPorts installs by default in /opt/local, whereas Homebrew installs in /usr/local. Since the command you are actually running is /opt/local/bin/wget, you probably have /opt/local/bin before /usr/local/bin in your PATH environment. Check it with:

$ echo $PATH

In such a case, any software installed with Homebrew is not used at all, if not called with its absolute path. So, try launching Homebrew's wget with its absolute path:

$ /usr/local/bin/wget 

If it is working in this way, put /usr/local/bin as first folder in your PATH environment, by modifying ~/.profile or ~/.bash_profile file.