Unable to run hugo: /usr/bin/hugo: No such file or directory

I installed the latest hugo 0.121.2 from snap. When I run a hugo command (hugo version) I get:

bash: /usr/bin/hugo: No such file or directory

Previously I removed the snap to install hugo from .deb-package, but could not get the latest version this way. So I installed the snap again.

dpkg -L hugo
/usr
/usr/local
/usr/local/bin
/usr/local/bin/hugo

dpkg -L hugo | grep bin
/usr/local/bin
/usr/local/bin/hugo

which hugo
/usr/local/bin/hugo

whereis hugo
hugo: /usr/local/bin/hugo

What might the problem be and how can I solve it?

When you install Hugo as a snap package on Ubuntu, its exec path is /snap/bin/hugo.

echo $PATH

Does it include /snap/bin ?

I get this output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

OK, so /snap/bin is in your PATH, but it’s the last path to be checked. So, if Hugo is installed as both a snap and a deb package, running which hugo will show /usr/bin/hugo.

If both are installed properly, whereis hugo should display:

hugo: /usr/bin/hugo /snap/bin/hugo 

If I were you, I would uninstall both and start over:

sudo apt remove hugo
sudo snap remove hugo
sudo snap install hugo
which hugo
hugo version
1 Like

Tried that. Something seems to change:

which hugo
/snap/bin/hugo

But the original error is still there:

hugo version
bash: /usr/bin/hugo: No such file or directory

Does this work?

/snap/bin/hugo version

Do you have an alias somewhere? For example:

alias hugo='/usr/bin/hugo'

Maybe in $HOME/.bashrc or $HOME/.bash_aliases or $HOME/.profile?

You can check with:

type hugo

I’m not sure about that. I tried to run your commands. At least it shows the current version of hugo:

/snap/bin/hugo version
hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154+extended linux/amd64 BuildDate=2024-01-05T12:21:15Z VendorInfo=snap:0.121.2

It doesn’t seem like there is an alias, right?

type hugo
hugo is /snap/bin/hugo

Run this:

hash -d hugo
which hugo

Welcome to the bash hash cache. See hash --help.

When you open a new terminal the hash cache is empty, so that should work too.

Hm … which hugo still gives me /snap/bin/hugo.
I get the same error when I try hugo version

I also tried to create an alias (if I understand your command correctly) with alias hugo='/usr/bin/hugo' and when I check with type hugo I do correctly get hugo is aliased to '/usr/bin/hugo'
But I still get the same error when I try hugo version

bash: /usr/bin/hugo: No such file or directory

No no no. Undo what you did. We don’t want any aliases.

At this point I can’t figure out what you’ve done.

I can think of two reasons for this message:

bash: /usr/bin/hugo: No such file or directory
  1. You have an alias somewhere, where “hugo” is aliased to /usr/bin/hugo
  2. Your bash hash cache points to the wrong exec path. That should be resolved by hash -d hugo, or by opening a new terminal.

Other than that, I have no idea.

1 Like

The strangest thing. I tried to open my terminal now a day later and typed in hugo version as the first thing. And suddenly I don’t get the error but this output:

hugo v0.121.2-6d5b44305eaa9d0a157946492a6f319da38de154+extended linux/amd64 BuildDate=2024-01-05T12:21:15Z VendorInfo=snap:0.121.2

I am also able to continue the Quick start guide and have now progressed to setting up a most basic website on my localhost with a bit of test content.

Do you think it might be the existence of the alias that made this possible after all - and it only worked after I had opened a new terminal? Might this cause problems for me in the future so that I should be cautious going forward because I might have to undo a lot of things as I start building a website?

See my previous response.

Exec paths, hashes, and your PATH env variable are pretty basic Linux concepts. The fact that you are having problems with them makes me distrust your setup.

I’ll be the first to admit I have very little clue about all this. I’m just trying to learn. Thanks for you time though!

Hello, @jmooring

I met the same situation that @malte had, and the problem was solved naturally itself.

At first, I open a terminal (Let’s say T1) and have a apt version of hugo already installed.

  1. In order to install the snap version of hugo, I followed the instructions above by runnning the following commands:

    sudo apt remove hugo
    sudo apt autoremove libsass1
    which hugo
    snap search hugo
    sudo snap install hugo
    which hugo
    hugo version
    echo $PATH
    whereis hugo
    /snap/bin/hugo version
    type hugo
    
    Click to expand the log
    hwhsu1231@vb-kubuntu:~$ sudo apt remove hugo
    正在讀取套件清單... 完成
    正在重建相依關係... 完成  
    正在讀取狀態資料... 完成  
    The following package was automatically installed and is no longer required:
      libsass1
    Use 'sudo apt autoremove' to remove it.
    下列套件將會被【移除】:
      hugo
    升級 0 個,新安裝 0 個,移除 1 個,有 1 個未被升級。
    此操作完成之後,會空出 49.6 MB 的磁碟空間。
    是否繼續進行 [Y/n]? [Y/n] y
    (讀取資料庫 ... 目前共安裝了 350640 個檔案和目錄。)
    正在移除 hugo (0.92.2-1ubuntu0.1)……
    執行 man-db (2.10.2-1) 的觸發程式……
    hwhsu1231@vb-kubuntu:~$ sudo apt autoremove libsass1
    正在讀取套件清單... 完成
    正在重建相依關係... 完成  
    正在讀取狀態資料... 完成  
    下列套件將會被【移除】:
      libsass1
    升級 0 個,新安裝 0 個,移除 1 個,有 1 個未被升級。
    此操作完成之後,會空出 3,130 kB 的磁碟空間。
    是否繼續進行 [Y/n]? [Y/n] y
    (讀取資料庫 ... 目前共安裝了 350593 個檔案和目錄。)
    正在移除 libsass1:amd64 (3.6.5-1ubuntu1)……
    執行 libc-bin (2.35-0ubuntu3.6) 的觸發程式……
    hwhsu1231@vb-kubuntu:~$ which hugo
    hwhsu1231@vb-kubuntu:~$ snap search hugo
    Name            Version  Publisher     Notes  Summary
    hugo            0.123.8  hugo-authors  -      A fast and flexible static site generator
    bissetii        1.8.0    zoralab       -      This package bissetii provides a way to install its Go themes.
    gotham          v0.13.0  gothamhq      -      An awesome and super fast Static Site Generator.
    quiqr           0.15.2   pimsnel       -      Hugo Powered CMS
    demo-hugo-site  0.1      ryanjyoder    -      Demo Hugo Site - Snap a hugo site
    hwhsu1231@vb-kubuntu:~$ sudo snap install hugo
    hugo 0.123.8 from Hugo Authors installed
    hwhsu1231@vb-kubuntu:~$ which hugo
    /snap/bin/hugo
    hwhsu1231@vb-kubuntu:~$ hugo version
    bash: /usr/bin/hugo: No such file or directory
    hwhsu1231@vb-kubuntu:~$ echo $PATH
    /home/hwhsu1231/gems/bin:/home/hwhsu1231/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/hwhsu1231/.local/share/JetBrains/Toolbox/scripts
    hwhsu1231@vb-kubuntu:~$ whereis hugo
    hugo: /snap/bin/hugo
    hwhsu1231@vb-kubuntu:~$ /snap/bin/hugo version
    hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=snap:0.123.8
    hwhsu1231@vb-kubuntu:~$ type hugo
    hugo is hashed (/usr/bin/hugo)
    hwhsu1231@vb-kubuntu:~$ 
    

    We can see that hugo version command failed, and the output of the last step type hugo is:

    hugo is hashed (/usr/bin/hugo)
    
  2. However, if I open a new terminal (Let’s say T2), and then run the following commands:

    which hugo
    hugo version
    type hugo
    
    Click to expand the log
    hwhsu1231@vb-kubuntu:~$ which hugo
    /snap/bin/hugo
    hwhsu1231@vb-kubuntu:~$ hugo version
    hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=snap:0.123.8
    hwhsu1231@vb-kubuntu:~$ type hugo
    hugo is hashed (/snap/bin/hugo)
    

    We can see that the hugo version works for T2 terminal, and the output of the type hugo is now:

    hugo is hashed (/snap/bin/hugo)
    
  3. And then, I go back to the T1 terminal, and then run the following commands:

    type hugo
    hash -d hugo
    type hugo
    hugo version
    
    Click to expand the log
    hwhsu1231@vb-kubuntu:~$ type hugo
    hugo is hashed (/usr/bin/hugo)
    hwhsu1231@vb-kubuntu:~$ hash -d hugo
    hwhsu1231@vb-kubuntu:~$ type hugo
    hugo is /snap/bin/hugo
    hwhsu1231@vb-kubuntu:~$ hugo version
    hugo v0.123.8-5fed9c591b694f314e5939548e11cc3dcb79a79c+extended linux/amd64 BuildDate=2024-03-07T13:14:42Z VendorInfo=snap:0.123.8
    

    We can see that the hugo version works for T1 terminal as well, and the output of type hugo is now:

    hugo is /snap/bin/hugo
    

Can you explain this phenomenon and conclude this topic?

Yes, as I mentioned in a previous reply, you are seeing the effects of the bash hash cache. See hash --help.

When you open a new terminal the hash cache is empty.

1 Like

You could also try hash -r in the current shell.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.