Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash: dotnet: command not found (.NET 6 installed on CentOS 7) #62208

Closed
diev opened this issue Nov 30, 2021 · 5 comments
Closed

bash: dotnet: command not found (.NET 6 installed on CentOS 7) #62208

diev opened this issue Nov 30, 2021 · 5 comments

Comments

@diev
Copy link

diev commented Nov 30, 2021

Description

"bash: dotnet: command not found" like closed #3846 after reinstall .NET6 over .NET5 on CentOS 7.9, and same issue #3603 on macOS.

Reproduction Steps

Take a clean CentOS 7.9 installation.
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
sudo yum install dotnet-sdk-5.0 (your page https://docs.microsoft.com/ru-ru/dotnet/core/install/linux-centos should be updated upto v6).
dotnet --info => .NET5
It's ok.
...
Now trying to update with an over-installation of same 6.0:
sudo yum install dotnet-sdk-6.0
dotnet --info => still .NET5 only? none of .NET6
It's wrong!
Many bad attempts to clean these installations to get 6.0, including the total erasing of folders...
sudo yum install dotnet-sdk-6.0 (expected to reinstall everything required)
dotnet --info => "bash: dotnet: command not found"

Expected behavior

dotnet

Actual behavior

bash: dotnet: command not found

Regression?

No response

Known Workarounds

sudo yum install dotnet-sdk-6.0
Test ls /usr/share/dotnet => "sdk sdk-manifests shared templates" (no dotnet installed)

Workaround:

wget https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh
cp -r -n .dotnet/* /usr/share/dotnet
ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
rm -rf .dotnet

Test ls /usr/share/dotnet => "dotnet host packs sdk sdk-manifests shared templates" (dotnet and two folders added)

Configuration

dotnet --info =>

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

Other information

Expected the running (first time or any later) of sudo yum install dotnet-sdk-6.0 will make additionally:

  • host/
  • packs/
  • dotnet
  • /usr/bin/dotnet

Or add some documentation near dotnet-install.sh (as it writes on its run: not recommended for the system install).

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Setup untriaged New issue has not been triaged by the area owner labels Nov 30, 2021
@am11
Copy link
Member

am11 commented Nov 30, 2021

I tested it in a clean environment:

# bash

$ mkdir foo && cd $_
$ cat > Dockerfile <<EOF
FROM centos:7

RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
RUN yum update -y

RUN yum install -y dotnet-sdk-5.0
RUN dotnet --info

RUN yum install -y dotnet-sdk-6.0

ENTRYPOINT dotnet --info
EOF

$ docker build -t test1 .

Then running docker run test1 gives:

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     centos
 OS Version:  7
 OS Platform: Linux
 RID:         centos.7-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  5.0.403 [/usr/share/dotnet/sdk]
  6.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

as expected.

So it might be something in your environment (variable like DOTNET_ROOT etc. is set) causing the issue?

@NikolaMilosavljevic
Copy link
Member

This is the same issue as in: #61849

The workaround is to create a symlink using the following command:

ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet

We have fixed this in 7.0: #62455

Fix for 6.0 will be ready soon.

@NikolaMilosavljevic NikolaMilosavljevic removed the untriaged New issue has not been triaged by the area owner label Dec 8, 2021
@Mohsnb
Copy link

Mohsnb commented Jan 28, 2022

I can fix it with this commands:

export DOTNET_ROOT=/usr/share/dotnet/
export PATH=$PATH:$DOTNET_ROOT

@jberry
Copy link

jberry commented Feb 2, 2022

In case more details are needed, it looks like the postuninstall scriptlet of the RPM is just missing it's "$1 == 0" guard around the symlink removal. And since the bugged script versions of the RPM are out there, just fixing this won't be enough to ensure the symlink exists with future updates.

It should be fixable by just adding the $1==0 safeguard in %postun (so it only removes the symlink if rpm is the last one being removed), as well as add a %posttrans so at the end, the new updated RPM ensures the symlink really does exist (i.e. one of these bugged 6.x versions didn't remove the symlink). No guard is needed there since %posttrans only runs if the RPM is still around:

Current:

%post -p /bin/sh
#!/usr/bin/env bash

if [[ -L /usr/local/bin/dotnet ]]; then
  rm /usr/local/bin/dotnet
fi
ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet



%postun -p /bin/sh
#!/usr/bin/env bash

if [[ -L /usr/local/bin/dotnet ]]; then
  rm /usr/local/bin/dotnet
fi

Fixed/recovery version:

%post -p /bin/sh
#!/usr/bin/env bash

if [[ -L /usr/local/bin/dotnet ]]; then
  rm /usr/local/bin/dotnet
fi
ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet

%postun -p /bin/sh
#!/usr/bin/env bash
if [ $1 == 0 ]; then
  if [[ -L /usr/local/bin/dotnet ]]; then
    rm /usr/local/bin/dotnet
  fi
fi

%posttrans
#!/usr/bin/env bash
if ! [[ -L /usr/local/bin/dotnet ]]; then
  ln -s /usr/share/dotnet/dotnet /usr/local/bin/dotnet
fi

@NikolaMilosavljevic
Copy link
Member

Closing as this was resolved long time ago.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants