dotnet-install.sh not adding dotnet command on Ubuntu - linux

I am not a Linux user so this might be a easy fix but I have tried the following:
first I install it using the command curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin for which I get the following result:
dotnet-install: .NET Core SDK version 2.1.403 is already installed.
dotnet-install: Adding to current process PATH:
/home/<!username!>/.dotnet. Note: This change will be visible only when sourcing script.
dotnet-install: Installation finished successfully.
I do . ~/.profile to reload the profile,
but even after this when I run dotnet I get the following error:
Command 'dotnet' not found, but can be installed with:
sudo snap install dotnet-sdk`
I was expecting the script to do everything and make dotnet available.

TLDR: curl | bash can not modify PATH so it will not add dotnet to your PATH. You need to add dotnet to your path manually. Add export PATH="$PATH:/home/<!username!>/.dotnet" to your ~/.profile (or ~/.bashrc or equivalent) and log out and log back in.
Long version:
When you run a command in the shell (for example, bash), the shell tries to find an executible with the name in the all the paths listed in the environment variable PATH. PATH is generally set to something like /bin:/usr/bin. So when you type a command like curl, your shell looks in both /bin and /usr/bin for an executible file named curl.
You can see what your PATH is by doing env | grep PATH or echo $PATH.
The other important piece of information is how environment variables propagate. It's quite simple, actually:
A program (or process) can only modify its own set of environment variables.
Any child processes that a process creates inherit its environment variables.
What this means is that a program that you execute can not modify the environment variables of another random program. The shell actually provides a special command, export to set its own environment variables (and any child processes it later creates will inherit those).
Note the output at the end of step 1.
Note: This change will be visible only when sourcing script.
If you run curl | bash, it runs bash as a child process. That child process can not modify the environment variables of the program that started it (the shell that invoked curl | bash). So it can not modify PATH to add the location of dotnet to it. It even (helpfully) tells you that it can't.
In step 2, you are reloading ~/.profile. But does it contain any commands to add dotnet to PATH? I dont think so. I know the dotnet-install.sh script has not historically added it. You need to add a line like
export PATH="$PATH:/home/<!username!>/.dotnet"
To your ~/.profile (or ~/.bashrc, or equivalent) manually.
Actually, I would write it as follows to make the change more portable to other users:
export PATH="$PATH:$HOME/.dotnet"

Try running this again:
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-2.2

Related

How to stop the Cygwin terminal from forgetting the environment when opening it in a non-home folder?

I got Ocaml for Windows which comes prepackaged with Cygwin. Since I wanted to be able to open mintty from the command line in the current directory, so I added it to PATH and then just running mintty does the trick. While this causes it to open in the current directory the problem is that when I run any of the Ocaml executables like opam I get an error.
Marko#Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
bash: opam: command not found
When I run it using mintty - like the shortcut does, this in fact works.
Marko#Lain ~
$ cd "E:\Webdev\Ocaml\todolist"
Marko#Lain /cygdrive/e/Webdev/Ocaml/todolist
$ opam
usage: opam [--version]
[--help]
<command> [<args>]
The most commonly used opam commands are:
init Initialize opam state, or set init options.
list Display the list of available packages.
show Display information about specific packages.
install Install a list of packages.
remove Remove a list of packages.
update Update the list of available packages.
upgrade Upgrade the installed package to latest version.
config Display configuration options for packages.
repository Manage opam repositories.
switch Manage multiple installation prefixes.
pin Pin a given package to a specific version or source.
admin Tools for repository administrators
See 'opam help <command>' for more information on a specific command.
What do I have to do so that I get this behavior normally?
Also, since mintty runs a terminal in a standalone window, it would be better to run bash, but bash - does not work for me. After I get this to work, I'd like to add bash to my list of VS Code shells and for that I'd need to understand how to run it in an arbitrary directory from the command line while keeping its memory of the home environment.
This command mintty - start your shell as login one.
If you run a not-login shell, most of the configuration script are not read, and enviroment is taken from the father process, but of course your link fails as Windows can not provide a proper one.
If you want to be able to open a login shell from explorer the best way is to install chere package
$ chere -h
/usr/bin/chere version 1.4
Usage:
/usr/bin/chere -<iuxlrhv> [-lracnmpf12] [-t <term>] [-s <shell>]
[-d <display> ] [-o <options>] [-e <menutext>]
Adds the stated terminal/shell combination to the folder context menu
This allows you to right click a folder in Windows Explorer and open
a Cygwin shell in that folder.
Options:
i - Install
u - Uninstall
x - Freshen eXisting entries
l - List currently installed chere items
r - Read all chere registry entries to stdout
a - All users
c - Current user only
n - Be Nice and provide Control Panel uninstall option (Default)
m - Minimal, no Control Panel uninstall
p - Print regtool commands to stdout rather than running them
f - Force write (overwrite existing, ignore missing files)
1 - Start using registry one-liners. This doesn't work with ash,
tcsh or network shares.
2 - Start via bash script. Relies on windows to change directory,
and login scripts avoiding doing a cd /home/Marco
h - Help
v - Version
t <term> - Use terminal term. Supported terminals are:
cmd rxvt mintty xterm urxvt
s <shell> - Use the named shell. Supported shells are:
ash bash cmd dash fish mksh pdksh posh tcsh zsh passwd
d <display> - DISPLAY to use (xterm, urxvt). Defaults to :0.
Set to env to use the runtime environment variable.
o <options> - Add <options> to the terminal startup command.
If more than one option is specified, they should all be
contained within a single set of quotes.
e <menutext> - Use <menutext> as the context menu text.
See the man page for more detail.
You can than install your preferred or default shell on explorer right click menu as an additional item. It will open a login shell in the chosen directory.

Activate virtualenv using alias

I can activate my python virtual environment from it's folder by entering . bin/activate. I'd like to instead type a single word alias, such as shazam, from the home folder (or anywhere else) that activates the environment, changes to my master project folder, and lists my projects.
I tried creating an alias in .bashrc that pointed to an .sh file containing:
cd ~/path-to-virtual-environment
. bin/activate
cd ~/path-to-master-project-folder
ls -a
I was getting a permission denied error, so I ran chmod u+x <script file>. The script now runs, but the VE does not activate and while the project folders are listed, the shell is not in the master project folder. I would appreciate some guidance. Thanks.
Recreate all your environments in ~/.virtualenvs and install virtualenvwrapper. The command to activate an env is workon shazam. Command line completion is supported.
Now about your problem: you've tried to activate an environment in a shell script. That doesn't work because shell scripts run with another shell and env activation change their environments, not the current. I.e., the environment briefly activated but then at the end of the script the new shell exits and the environment deactivated.
There are two ways to overcome this.
Use aliases or shell functions instead of scripts — they are the only way to change the current shell's environment.
Run interactive shell at the end of your script (exec $SHELL). It inherits activated environment and gives you a command prompt. To deactivate simply exit the shell (exit or [Ctrl]+[D].).

Specify which shell Yarn uses for running scripts

My package.json has a script in it like this:
"buildTslint": "node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts",
Note the {,helpers/}*.ts part, this is called Brace Expansion and is only possible in bash, not sh.
When running yarn buildTslint I get the following output:
# yarn buildTslint
yarn buildTslint v0.22.0
$ node_modules/typescript/bin/tsc node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts
error TS6053: File 'node_modules/awesomeLibrary_node_tslint/{,helpers/}*.ts' not found.
error Command failed with exit code 2.
It seems that Yarn uses sh to execute these scripts, but I'd like to use bash for this, to be able to use brace expansion.
yarn version 1.19 added support for a new config parameter script-shell. You can now do the following:
yarn config set script-shell /bin/bash
It may launch the command using system function see also man 3 system.
To see which system call is used :
strace yarn ...
system uses fork+exec+wait and the exec family functions uses shell /bin/sh
to use bash the command can be changed to bash -c 'command ..'
Yarn doesn't yet provide a way to configure the default shell used for running scripts, see: https://github.com/yarnpkg/yarn/issues/4248
However, since yarn uses Node for spawning its processes, you can work around that by changing the default shell that Node itself uses.
On Ubuntu, if you have root permissions, you can do this by changing the symlink /bin/sh to point to something other than dash:
sudo ln -sf /bin/bash /bin/sh
In Git-bash in Windows, you can change the COMSPEC environment variable to something other than C:\Windows\system32\cmd.exe, but I haven't gotten that to work for me.
See also:
Force node to use git bash on windows

Python3 no such file or directory

I am trying to make python3 executable scripts and run them from shell.I have python 3.4.0 installed on my system.
So, I added '/home/spandan/python_codes' directory to PYTHONPATH, as I am planning to keep my scripts and modules here.
However, while trying to execute these, the above error is thrown by the system, and the scripts wont execute unless I go into the python_codes directory and then execute them.
Executing python program : Here I found out that PYTHONPATH is irrelevant while making scripts, and also how to set the python shebang. So I set mine as #!/usr/bin/env python3.4.0
Is it correct?
You don't have to put your python codes in a global path. Just make your python 3.4 interpreter interpreter available globally. For that, edit .bash_profile or .bashrc file in your home directory and add the following line:
export PATH=${PATH}:/usr/bin/python3
That will make python3 executable irrespective of your current working directory.
In order to execute code from your codes directory, you just have to write:
$ python3 ./your_code.py
Another way is to add the shebang at the top of your code as
#/usr/bin/python3
and change the permission to executable by the current user (by default it will not have execute permission).
$ chmod 744 your_code.py
and then executing the script directly as
$ your_code.py
I hope I could address your problem.
Another way to do it is to use python-is-python2 or python-is-python3 debian packages with /usr/bin/env python sheabang.
This option will let the end user select which interpreter he want to use while maintaining your code versionless and avoiding some people to install unwanted interpreter versions.
As an example, run this commands to make a sample file:
cat << EOF > version.py && chmod +x version.py
#!/usr/bin/env python
import sys
print(sys.version)
EOF
And run the following command if you want to set python2 as default:
sudo apt install python-is-python2
Or run this command if you want to set python3 as default:
sudo apt install python-is-python3
Finally you could see the python interpreter version that you have been selected by running:
./version.py
The only drawback of this solution is that you could make your python scripts compatible across python interpreter versions, but thats your decision!
You can install which you want and change from python2 to python3 and vice- versa as you want, but the idea is to fix a python interpreter version in a system and not change it again unless definitive upgrade.
References:
https://askubuntu.com/questions/1296790/python-is-python3-package-in-ubuntu-20-04-what-is-it-and-what-does-it-actually

Open GTS build failed

Every thing is okay (Opengts dir & tomcat dir have permission 777) but i am getting this error again & again, why--
executing # sudo ant all then i get this error
BUILD FAILED
/usr/local/OpenGTS_2.4.5/build.xml:111: CATALINA_HOME environment variable has not been defined.
(make sure CATALINA_HOME is defined and exported to the list of environment variables)
I got the this msg when starting the tomcat
sudo ./startup.sh
Using CATALINA_BASE: /usr/local/apache-tomcat-6.0.36
Using CATALINA_HOME: /usr/local/apache-tomcat-6.0.36
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-6.0.36/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/apache-tomcat-6.0.36/bin/bootstrap.jar
Any one have the solution please tell me how to fix this error.
Try to configure OpenGTS in your home directory (rather than /usr/local/).
And use ant all command (not sudo ant all).
Good Lock.. :)
First run this command:
echo $CATALINA_HOME
It should give you the path to your tomcat directory, which I'm assuming is /usr/local/apache-tomcat-6.0.36, but if you see a different path, or if the response is blank, try running this command:
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.36
If you read the OpenGTS Configuration Manual, it talks about the CATALINA_HOME environment variable for Linux in section 2.4a. There are other environment variables too that you must set to install OpenGTS successfully (All mentioned in the manual).
To solve this problem, ensure the OpenGTS2.6.x has all files and directories to user:group same as logged in user. then run / ant all command
Please note that "sudo ant all" doesn't work.
Use this command to change ownership of OpenGTS files/dir
/usr/local/OpenGTS2.6.2> cd ..
sudo chown -R ranjan:ranjan OpenGTS2.6.2
change ranjan to your username: group name
/usr/local/OpenGTS2.6.2> ant all
It will work.
Try to install tomcat7 rather than tomcat6 via command line
apt-get update
apt-get install tomcat7
Configure CATALINA_HOME by
export CATALINA_HOME=/usr/share/tomcat7

Resources